{"id":11056,"date":"2022-10-31T07:00:47","date_gmt":"2022-10-30T22:00:47","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=11056"},"modified":"2022-11-21T05:44:29","modified_gmt":"2022-11-20T20:44:29","slug":"laravel-react-%e3%81%a7%e3%81%8a%e5%95%8f%e3%81%84%e5%90%88%e3%82%8f%e3%81%9b%e3%83%95%e3%82%a9%e3%83%bc%e3%83%a0%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b%ef%bc%88enum%e3%80%81%e3%83%90%e3%83%aa%e3%83%87","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=11056","title":{"rendered":"Laravel + React \u3067\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u308b\uff08Enum\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3001\u65e5\u672c\u8a9e\u5316\u3082\uff01\uff09"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593\u00a0<a href=\"https:\/\/blog.capilano-fw.com\/?p=10909\" target=\"_blank\" rel=\"noopener\">Laravel + React \u3067\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30fb\u30c1\u30e3\u30c3\u30c8\u3092\u3064\u304f\u308b<\/a> \u3068\u3044\u3046\u8a18\u4e8b\u304c\u601d\u3044\u306e\u307b\u304b\u591a\u304f\u8aad\u3093\u3067\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002\uff08\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u2757\uff09<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u308c\u306b\u8abf\u5b50\u3065\u3044\u3066\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u3067\u3059\u304c\u3001\u5c11\u3057\u9577\u3081\u30b3\u30fc\u30c9\u3092\u4f7f\u3063\u305f\u8a18\u4e8b\u3092\u516c\u958b\u3057\u3066\u307f\u3088\u3046\u3068\u3044\u3046\u6c17\u5206\u306b\u306a\u308a\u307e\u3057\u305f\uff08\u7b11\uff09<\/p>\n<p>\u3057\u304b\u3057\u3001\u300c<strong>\u8907\u96d1\u306a\u5185\u5bb9 + \u9577\u3044\u30b3\u30fc\u30c9<\/strong>\u300d\u3068\u306a\u308b\u3068\u5473\u306e\u6fc3\u3059\u304e\u308b\u6599\u7406\u307f\u305f\u3044\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067\u3001\u30c6\u30fc\u30de\u306f\u3068\u3066\u3082\u8584\u5473\u306e\u300c<strong>\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0<\/strong>\u300d\u3067\u3084\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u300c<strong>Laravel + React<\/strong>\u300d\u3067\u7d30\u90e8\u306b\u3082\u3053\u3060\u308f\u3063\u305f\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\ud83d\ude04\u2728<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4328 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3.png\" alt=\"\" width=\"364\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3.png 364w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3-300x264.png 300w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/>\u300c\u8155\u6642\u8a08\u304c\uff12\u3064\u3068\u3082<br \/>\n\u96fb\u6c60\u5207\u308c\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u2757\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 9.x\u3001React\u3001Vite\u3001Inertia.js\u3001TailwindCSS\u3001<strong>PHP 8.1<\/strong><\/p>\n<h1>\u30b0\u30eb\u30fc\u30d7\uff08Enum\uff09\u3092\u3064\u304f\u308b<\/h1>\n<p>\u307e\u305a\u306f<code>Enum<\/code>\u3067\u4ee5\u4e0b\u306e\u300c<strong>\u304a\u554f\u3044\u5408\u308f\u305b\u306e\u7a2e\u985e<\/strong>\u300d\u30b0\u30eb\u30fc\u30d7\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5546\u54c1\u306b\u95a2\u3059\u308b\u304a\u554f\u3044\u5408\u308f\u305b<\/li>\n<li>\u3054\u6ce8\u6587\u306b\u95a2\u3059\u308b\u304a\u554f\u3044\u5408\u308f\u305b<\/li>\n<li>\u30b5\u30dd\u30fc\u30c8\u306b\u95a2\u3059\u308b\u304a\u554f\u3044\u5408\u308f\u305b<\/li>\n<li>\u305d\u306e\u4ed6\u306e\u304a\u554f\u3044\u5408\u308f\u305b<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001<code>Enum<\/code>\u3068\u306f\u300c<strong>\u30b0\u30eb\u30fc\u30d7\u69cb\u6210<\/strong>\u300d\u3092\u5148\u306b\u6c7a\u3081\u3066\u304a\u3051\u308b\u3082\u306e\u3067\u3001\u7c21\u5358\u306b\u8a00\u3046\u3068\u300c<strong>\u3044\u3084\u3001\u305d\u308c\u30b0\u30eb\u30fc\u30d7\u306b\u5165\u3063\u3066\u306a\u3044\u304b\u3089\uff01<\/strong>\u300d\u3068\u30a8\u30e9\u30fc\u304c\u51fa\u308b\uff08\u3064\u307e\u308a\u3001\u304a\u304b\u3057\u306a\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3053\u306a\u3044\u3088\u3046\u306b\u3067\u304d\u308b\uff09\u30b9\u30b0\u30ec\u30e2\u30ce\u3067\u3059\u3002<\/p>\n<p><code>PHP 8.1<\/code>\u304b\u3089\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u307e\u305a\u306f<code>Enum<\/code>\u304b\u3089\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<p><strong>app\/Enums\/ContactType.php<\/strong><\/p>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Enums;<\/strong>\r\n\r\n<strong>use Illuminate\\Support\\Collection;<\/strong>\r\n\r\n<strong>enum ContactType: int<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    \/\/ ID<\/strong>\r\n<strong>    case Question = 100;<\/strong>\r\n<strong>    case Order = 200;<\/strong>\r\n<strong>    case Support = 300;<\/strong>\r\n<strong>    case Other = 9900;<\/strong>\r\n\r\n<strong>    public function name(): string<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return match ($this) {<\/strong>\r\n<strong>            self::Question =&gt; '\u5546\u54c1\u306b\u95a2\u3059\u308b\u304a\u554f\u3044\u5408\u308f\u305b',<\/strong>\r\n<strong>            self::Order =&gt; '\u3054\u6ce8\u6587\u306b\u95a2\u3059\u308b\u304a\u554f\u3044\u5408\u308f\u305b',<\/strong>\r\n<strong>            self::Support =&gt; '\u30b5\u30dd\u30fc\u30c8\u306b\u95a2\u3059\u308b\u304a\u554f\u3044\u5408\u308f\u305b',<\/strong>\r\n<strong>            self::Other =&gt; '\u305d\u306e\u4ed6\u306e\u304a\u554f\u3044\u5408\u308f\u305b',<\/strong>\r\n<strong>        };<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public static function collection(): Collection<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $collection = collect();<\/strong>\r\n\r\n<strong>        foreach (self::cases() as $case) {<\/strong>\r\n\r\n<strong>            $collection-&gt;push([<\/strong>\r\n<strong>                'id' =&gt; $case-&gt;value,<\/strong>\r\n<strong>                'name' =&gt; $case-&gt;name(),<\/strong>\r\n<strong>            ]);<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return $collection;<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u300c\u304a\u554f\u3044\u5408\u308f\u305b\u306e\u7a2e\u985e\u300d\u304c\u4fbf\u5229\u306b\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff01<\/p>\n<h1>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b<\/h1>\n<p>\u6b21\u306b\u3001\u300c<strong>\u30d5\u30a9\u30fc\u30e0\u304b\u3089\u9001\u4fe1\u3055\u308c\u305f\u30c7\u30fc\u30bf\u304c\u672c\u5f53\u306b\u6b63\u3057\u3044\u9001\u4fe1\u306a\u306e\u304b\uff1f<\/strong>\u300d\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u305f\u3081\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:request ContactRequest<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u5c02\u7528\u306e<code>FormRequest<\/code>\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Http\/Requests\/ContactRequest.php<\/strong><\/p>\n<pre><strong>&lt;?php\r\n\r\nnamespace App\\Http\\Requests;\r\n\r\nuse App\\Enums\\ContactType;\r\nuse Illuminate\\Foundation\\Http\\FormRequest;\r\nuse Illuminate\\Validation\\Rules\\Enum;\r\n\r\nclass ContactRequest extends FormRequest\r\n{\r\n    \/**\r\n     * Determine if the user is authorized to make this request.\r\n     *\r\n     * @return bool\r\n     *\/\r\n    public function authorize()\r\n    {\r\n        return true;\r\n    }\r\n\r\n    \/**\r\n     * Get the validation rules that apply to the request.\r\n     *\r\n     * @return array&lt;string, mixed&gt;\r\n     *\/\r\n    public function rules()\r\n    {\r\n        return [\r\n            'subject_id' =&gt; [\r\n                'required',\r\n                new Enum(ContactType::class)\r\n            ],\r\n            'name' =&gt; [\r\n                'required',\r\n                'string',\r\n                'max:255',\r\n            ],\r\n            'email' =&gt; [\r\n                'required',\r\n                'string',\r\n                'email',\r\n                'max:255',\r\n            ],\r\n            'message' =&gt; [\r\n                'required',\r\n                'string',\r\n                'max:1000',\r\n            ],\r\n            'url' =&gt; [\r\n                'nullable',\r\n                'url',\r\n                'max:255',\r\n            ],\r\n        ];\r\n    }\r\n}<\/strong><\/pre>\n<p><code>Enum<\/code>\u304c\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30fb\u30eb\u30fc\u30eb\u306b\u7528\u610f\u3055\u308c\u3066\u308b\u306e\u3067\u7c21\u5358\u306b\u30c1\u30a7\u30c3\u30af\u3067\u304d\u307e\u3059\u306d\ud83d\udc4d \u3055\u3059\u304c<code>Laravel<\/code>\u3067\u3059\u2757<\/p>\n<h1>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u3001\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:control ContactController<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Http\/Controllers\/ContactController.php<\/strong><\/p>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Http\\Controllers;<\/strong>\r\n\r\n<strong>use App\\Enums\\ContactType;<\/strong>\r\n<strong>use App\\Http\\Requests\\ContactRequest;<\/strong>\r\n<strong>use App\\Mail\\Contacted;<\/strong>\r\n<strong>use Illuminate\\Http\\Request;<\/strong>\r\n<strong>use Illuminate\\Support\\Facades\\Mail;<\/strong>\r\n<strong>use Inertia\\Inertia;<\/strong>\r\n\r\n<strong>class ContactController extends Controller<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    public function create()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $contact_types = ContactType::collection();<\/strong>\r\n\r\n<strong>        return Inertia::render('Contact\/Create', [<\/strong>\r\n<strong>            'contactTypes' =&gt; $contact_types,<\/strong>\r\n<strong>        ]);<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function store(ContactRequest $request)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $subject = ContactType::from($request-&gt;subject_id)-&gt;name(); \/\/ Enam \u304b\u3089\u304a\u554f\u3044\u5408\u308f\u305b\u306e\u7a2e\u985e\u540d\u3092\u53d6\u5f97<\/strong>\r\n<strong>        $params = [<\/strong>\r\n<strong>            'subject' =&gt; $subject,<\/strong>\r\n<strong>            'name' =&gt; $request-&gt;name,<\/strong>\r\n<strong>            'email' =&gt; $request-&gt;email,<\/strong>\r\n<strong>            'message' =&gt; $request-&gt;message,<\/strong>\r\n<strong>            'url' =&gt; $request-&gt;url,<\/strong>\r\n<strong>        ];<\/strong>\r\n\r\n<strong>        try {<\/strong>\r\n\r\n<strong>            Mail::send(new Contacted($params)); \/\/ \u30e1\u30fc\u30eb\u9001\u4fe1<\/strong>\r\n\r\n<strong>        } catch (\\Exception $e) {<\/strong>\r\n\r\n<strong>            throw $e;<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return to_route('contact.complete');<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function complete()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return Inertia::render('Contact\/Complete');<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u3053\u306e\u4e2d\u3067\uff08\u5c11\u3057\uff1f\uff1f\uff09\u91cd\u8981\u306a\u306e\u304c\u3001<code>Enum<\/code>\u306e\u53d6\u5f97\u3092\u3057\u3066\u3044\u308b<code>ContactType::from()<\/code>\u306e\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p>\u3053\u3046\u3084\u3063\u3066\u8a72\u5f53\u3059\u308b<code>Enum<\/code>\u3092\u53d6\u5f97\u3057\u3001\u3055\u3089\u306b<code>name()<\/code>\u3067\u540d\u524d\u3092\u53d6\u5f97\u3057\u3066\u3044\u308b\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u3084\u3063\u3071\u308a<code>Enum<\/code>\u306f\u4fbf\u5229\u3067\u3059\u306d\u2757<\/p>\n<h1>\u30e1\u30fc\u30eb\u9001\u4fe1\u90e8\u5206\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u3001\u5148\u307b\u3069\u306e\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u5185\u3067\u4f7f\u3063\u305f<code>Mailable<\/code>\uff08\u30e1\u30fc\u30eb\u9001\u4fe1\u90e8\u5206\u3002\u4eca\u56de\u306f<code>Laravel 9.35<\/code>\u304b\u3089\u4f7f\u3048\u308b\u65b0\u30d1\u30bf\u30fc\u30f3\u3067\u3059\uff09\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:mail Contacted<\/strong><\/pre>\n<p><code>Mailable<\/code>\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Mail\/Contacted.php<\/strong><\/p>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Mail;<\/strong>\r\n\r\n<strong>use Illuminate\\Bus\\Queueable;<\/strong>\r\n<strong>use Illuminate\\Contracts\\Queue\\ShouldQueue;<\/strong>\r\n<strong>use Illuminate\\Mail\\Mailable;<\/strong>\r\n<strong>use Illuminate\\Mail\\Mailables\\Address;<\/strong>\r\n<strong>use Illuminate\\Mail\\Mailables\\Content;<\/strong>\r\n<strong>use Illuminate\\Mail\\Mailables\\Envelope;<\/strong>\r\n<strong>use Illuminate\\Queue\\SerializesModels;<\/strong>\r\n\r\n<strong>class Contacted extends Mailable<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    use Queueable, SerializesModels;<\/strong>\r\n\r\n<strong>    \/**<\/strong>\r\n<strong>     * Create a new message instance.<\/strong>\r\n<strong>     *<\/strong>\r\n<strong>     * @return void<\/strong>\r\n<strong>     *\/<\/strong>\r\n<strong>    public function __construct(<\/strong>\r\n<strong>        private array $params \/\/ \u2190 PHP 8 \u304b\u3089\u306f\u81ea\u52d5\u3067 $this-&gt;params \u306b\u683c\u7d0d\u3067\u304d\u308b<\/strong>\r\n<strong>    )<\/strong>\r\n<strong>    {}<\/strong>\r\n\r\n<strong>    \/**<\/strong>\r\n<strong>     * Get the message envelope.<\/strong>\r\n<strong>     *<\/strong>\r\n<strong>     * @return \\Illuminate\\Mail\\Mailables\\Envelope<\/strong>\r\n<strong>     *\/<\/strong>\r\n<strong>    public function envelope()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        \/\/ \u2193\u2193\u2193 \u672c\u6765\u306f .env \u3084 \u30b3\u30f3\u30d5\u30a3\u30b0\u306b\u30bb\u30c3\u30c8\u3059\u308b\u3079\u304d\u3067\u3059<\/strong>\r\n<strong>        $from = new Address('from@example.com', '\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0');<\/strong>\r\n<strong>        $to = [new Address('admin@example.com', '\u7ba1\u7406\u8005')];<\/strong>\r\n\r\n<strong>        return new Envelope(<\/strong>\r\n<strong>            from: $from,<\/strong>\r\n<strong>            to: $to,<\/strong>\r\n<strong>            subject: '\u304a\u554f\u3044\u5408\u308f\u305b\u304c\u3042\u308a\u307e\u3057\u305f',<\/strong>\r\n<strong>        );<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    \/**<\/strong>\r\n<strong>     * Get the message content definition.<\/strong>\r\n<strong>     *<\/strong>\r\n<strong>     * @return \\Illuminate\\Mail\\Mailables\\Content<\/strong>\r\n<strong>     *\/<\/strong>\r\n<strong>    public function content()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return new Content(<\/strong>\r\n<strong>            view: 'emails.contacted',<\/strong>\r\n<strong>            with: [<\/strong>\r\n<strong>                'params' =&gt; $this-&gt;params,<\/strong>\r\n<strong>            ],<\/strong>\r\n<strong>        );<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    \/**<\/strong>\r\n<strong>     * Get the attachments for the message.<\/strong>\r\n<strong>     *<\/strong>\r\n<strong>     * @return array<\/strong>\r\n<strong>     *\/<\/strong>\r\n<strong>    public function attachments()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return [];<\/strong>\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p>\u203b \u65b0\u30d1\u30bf\u30fc\u30f3\u306e<code>Mailable<\/code>\u306e\u66f8\u304d\u65b9\u3001\u3059\u3063\u304d\u308a\u3057\u3066\u5206\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u306d\ud83d\udc4d<\/p>\n<p><strong>\u3010\u8ffd\u8a18\uff1a2022.11.21\u3011<\/strong>\u5f8c\u3067\u5b9f\u884c\u3057\u3066\u307f\u305f\u3068\u3053\u308d\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u304c\u3067\u307e\u3057\u305f\u306e\u3067\u4fee\u6b63\u3057\u307e\u3057\u305f\u3002\uff08<code>$to<\/code>\u306f\u3001\u914d\u5217\u3068\u3057\u3066\u30bb\u30c3\u30c8\u3057\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3088\u3046\u3067\u3059\uff09<\/p>\n<pre><strong>Email \"\u7ba1\u7406\u8005\" does not comply with addr-spec of RFC 2822.<\/strong><\/pre>\n<p>\u306a\u304a\u3001\u3053\u3053\u3067\u91cd\u8981\u306a\u306e\u304c<code>PHP 8.0<\/code>\u304b\u3089\u5c0e\u5165\u3055\u308c\u305f\u300c<strong>Class constructor property promotion<\/strong>\u300d\u3067\u3059\u3002<\/p>\n<p>\u3061\u3087\u3063\u3068\u5927\u5c64\u306a\u540d\u524d\u306b\u805e\u3053\u3048\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u300c<strong>\u30e1\u30f3\u30d0\u5909\u6570\u306e\u683c\u7d0d\u304c\u7701\u7565\u3067\u304d\u308b\u3088<\/strong>\u300d\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u3053\u308c\u307e\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306b\u5165\u3063\u3066\u304d\u305f\u5909\u6570\u3092\u3044\u3061\u3044\u3061\u683c\u7d0d\u3057\u3066\u3044\u305f\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<pre>class YourGreatClass\r\n{\r\n    <strong>private $params;<\/strong>\r\n    \r\n    public function __construct(<strong>array $params<\/strong>)\r\n    {\r\n        <strong>$this-&gt;params = $params; \/\/ \u2190 \u3053\u3053<\/strong>\r\n    }<\/pre>\n<p>\u3053\u308c\u304c\u7701\u7565\u3057\u3066\u3053\u308c\u3060\u3051\u3067OK\u306b\u306a\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u306d\u3002<\/p>\n<pre>public function __construct(\r\n    <strong>private array $params<\/strong>\r\n)<\/pre>\n<p>\u300c<strong>\u30b3\u30fc\u30c9\u304c\u6e1b\u308b \uff1d \u30d0\u30b0\u3082\u5c11\u306a\u304f\u306a\u308b<\/strong>\u300d\u3068\u3044\u3046\u3053\u3068\u306a\u306e\u3067\u305c\u3072\u6d3b\u7528\u3057\u3066\u3044\u304d\u305f\u3044\u3067\u3059\u306d\u3002\ud83d\ude04<\/p>\n<p>\u305d\u3057\u3066\u3001\u30e1\u30fc\u30eb\u6587\u9762\u3082\u30d3\u30e5\u30fc\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>resources\/views\/emails.contacted.blade.php<\/strong><\/p>\n<pre><strong>\u304a\u554f\u3044\u5408\u308f\u305b\u304c\u3042\u308a\u307e\u3057\u305f\u3002&lt;br&gt;\r\n\u4ee5\u4e0b\u304c\u5185\u5bb9\u306b\u306a\u308a\u307e\u3059\u3002&lt;br&gt;&lt;br&gt;\r\n\r\n&lt;strong&gt;\u304a\u554f\u3044\u5408\u308f\u305b\u306e\u7a2e\u985e&lt;\/strong&gt;\uff1a {{ $params['subject'] }}&lt;br&gt;\r\n&lt;strong&gt;\u304a\u540d\u524d&lt;\/strong&gt;\uff1a {{ $params['name'] }}&lt;br&gt;\r\n&lt;strong&gt;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9&lt;\/strong&gt;\uff1a {{ $params['email'] }}&lt;br&gt;\r\n&lt;strong&gt;URL&lt;\/strong&gt;:{{ $params['url'] }}&lt;br&gt;\r\n&lt;strong&gt;\u304a\u554f\u3044\u5408\u308f\u305b\u5185\u5bb9&lt;\/strong&gt;\uff1a &lt;br&gt;\r\n{!! nl2br($params['message']) !!}&lt;br&gt;&lt;br&gt;\r\n\r\n&lt;strong&gt;\u682a\u5f0f\u4f1a\u793e\u25cb\u25cb&lt;\/strong&gt;&lt;br&gt;\r\nhttps:\/\/example.com\/<\/strong><\/pre>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001\u79c1\u306f\u30e1\u30fc\u30eb\u9001\u4fe1\u30c6\u30b9\u30c8\u306b<code>MailCatcher<\/code>\u3092\u611b\u7528\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u305d\u3057\u3066\u3001<code>MailCatcher<\/code>\u3067\u9001\u4fe1\u3092\u3059\u308b\u306b\u306f<code>.env<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u8d77\u52d5\u3082\u5fd8\u308c\u305a\u306b\uff01\uff09<\/p>\n<pre>MAIL_MAILER=smtp\r\n<strong>MAIL_HOST=127.0.0.1<\/strong>\r\nMAIL_PORT=1025<\/pre>\n<p>\u203b \u3082\u3057 <a href=\"https:\/\/mailcatcher.me\/\" target=\"_blank\" rel=\"noopener\"><strong>MailCatcher<\/strong><\/a> \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u306a\u3044\u65b9\u306f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u304b\u3001<code>mailgun<\/code>\u306a\u3069\u306e\u30b5\u30fc\u30d3\u30b9\u3092\u5229\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u79c1\u306f\u89e3\u9664\u3092\u5fd8\u308c\u3066\u8ab2\u91d1\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u304c\u2026\ud83d\ude2b\uff09<\/p>\n<h1>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h1>\n<p>\u6b21\u306b\u3001\u30d3\u30e5\u30fc\uff08\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\uff09\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u3053\u3053\u3067<code>React<\/code>\u3092\u30d0\u30ea\u30d0\u30ea\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u3001\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u90e8\u5206\u3067\u3059\u3002<\/p>\n<p><strong>resources\/js\/Pages\/Contact\/Create.jsx<\/strong><\/p>\n<pre><strong>import {useState, useEffect} from 'react';<\/strong>\r\n<strong>import {Inertia} from '@inertiajs\/inertia';<\/strong>\r\n<strong>import FormLabel from '@\/Components\/FormLabel';<\/strong>\r\n<strong>import ErrorMessage from '@\/Components\/ErrorMessage';<\/strong>\r\n\r\n<strong>export default function Create(props) {<\/strong>\r\n\r\n<strong>    \/\/ Data<\/strong>\r\n<strong>    const [subjectId, setSubjectId] = useState('');<\/strong>\r\n<strong>    const [name, setName] = useState('');<\/strong>\r\n<strong>    const [email, setEmail] = useState('');<\/strong>\r\n<strong>    const [message, setMessage] = useState('');<\/strong>\r\n<strong>    const [url, setUrl] = useState('');<\/strong>\r\n<strong>    const contactTypes = props.contactTypes;<\/strong>\r\n\r\n<strong>    \/\/ Submit<\/strong>\r\n<strong>    const handleSubmit = () =&gt; {<\/strong>\r\n\r\n<strong>        if(confirm('\u9001\u4fe1\u3057\u307e\u3059\u3002\u3088\u308d\u3057\u3044\u3067\u3059\u304b\uff1f')) {<\/strong>\r\n\r\n<strong>            const data = {<\/strong>\r\n<strong>                subject_id: subjectId,<\/strong>\r\n<strong>                name: name,<\/strong>\r\n<strong>                email: email,<\/strong>\r\n<strong>                message: message,<\/strong>\r\n<strong>                url: url,<\/strong>\r\n<strong>            };<\/strong>\r\n\r\n<strong>            Inertia.post(<\/strong>\r\n<strong>                route('contact.store'),<\/strong>\r\n<strong>                data<\/strong>\r\n<strong>            )<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    };<\/strong>\r\n\r\n<strong>    \/\/ Errors<\/strong>\r\n<strong>    const errors = props.errors;<\/strong>\r\n<strong>    useEffect(() =&gt; {<\/strong>\r\n\r\n<strong>        if(Object.keys(errors).length &gt; 0) {<\/strong>\r\n\r\n<strong>            \/\/ \u30a8\u30e9\u30fc\u306e\u7b87\u6240\u307e\u3067\u81ea\u52d5\u3067\u30b9\u30af\u30ed\u30fc\u30eb\u3059\u308b<\/strong>\r\n<strong>            const errorElements = document.querySelectorAll('.error-message');<\/strong>\r\n<strong>            let topPositions = [];<\/strong>\r\n\r\n<strong>            [].forEach.call(errorElements, element =&gt; {<\/strong>\r\n\r\n<strong>                const top = element.getBoundingClientRect().top;<\/strong>\r\n<strong>                topPositions.push(top);<\/strong>\r\n\r\n<strong>            });<\/strong>\r\n\r\n<strong>            const scrollTop = Math.min(...topPositions) - 180;<\/strong>\r\n<strong>            window.scrollTo({<\/strong>\r\n<strong>                top: scrollTop,<\/strong>\r\n<strong>                behavior: 'smooth'<\/strong>\r\n<strong>            });<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    }, [errors]);<\/strong>\r\n\r\n<strong>    return (<\/strong>\r\n<strong>        &lt;div className=\"p-5\"&gt;<\/strong>\r\n<strong>            &lt;h1&gt;\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0&lt;\/h1&gt;<\/strong>\r\n<strong>            &lt;div className=\"border p-4 bg-gray-50 w-full md:w-1\/2\"&gt;<\/strong>\r\n<strong>                &lt;div className=\"mb-3\"&gt;<\/strong>\r\n<strong>                    &lt;FormLabel required&gt;\u304a\u554f\u3044\u5408\u308f\u305b\u306e\u7a2e\u985e&lt;\/FormLabel&gt;<\/strong>\r\n<strong>                    &lt;select name=\"type\" className=\"form-control text-smw-full md:w-1\/2\" value={subjectId} onChange={e =&gt; setSubjectId(e.target.value)}&gt;<\/strong>\r\n<strong>                        &lt;option value=\"\"&gt;\u25bc \u9078\u629e\u3057\u3066\u304f\u3060\u3055\u3044&lt;\/option&gt;<\/strong>\r\n<strong>                        {contactTypes.length &gt; 0 &amp;&amp; contactTypes.map(contactType =&gt; (<\/strong>\r\n<strong>                            &lt;option key={contactType.id} value={contactType.id}&gt;{contactType.name}&lt;\/option&gt;<\/strong>\r\n<strong>                        ))}<\/strong>\r\n<strong>                    &lt;\/select&gt;<\/strong>\r\n<strong>                    &lt;ErrorMessage message={errors.subject_id}&gt;&lt;\/ErrorMessage&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>                &lt;div className=\"mb-3\"&gt;<\/strong>\r\n<strong>                    &lt;FormLabel required&gt;\u304a\u540d\u524d&lt;\/FormLabel&gt;<\/strong>\r\n<strong>                    &lt;input type=\"text\" className=\"w-full md:w-1\/2\" value={name} onChange={e =&gt; setName(e.target.value)} \/&gt;<\/strong>\r\n<strong>                    &lt;ErrorMessage message={errors.name}&gt;&lt;\/ErrorMessage&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>                &lt;div className=\"mb-3\"&gt;<\/strong>\r\n<strong>                    &lt;FormLabel required&gt;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9&lt;\/FormLabel&gt;<\/strong>\r\n<strong>                    &lt;input type=\"email\" className=\"w-full md:w-1\/2\" value={email} onChange={e =&gt; setEmail(e.target.value)} \/&gt;<\/strong>\r\n<strong>                    &lt;ErrorMessage message={errors.email}&gt;&lt;\/ErrorMessage&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>                &lt;div className=\"mb-3\"&gt;<\/strong>\r\n<strong>                    &lt;FormLabel required&gt;\u304a\u554f\u3044\u5408\u308f\u305b\u5185\u5bb9&lt;\/FormLabel&gt;<\/strong>\r\n<strong>                    &lt;textarea name=\"body\" className=\"form-control w-full block\" rows=\"5\" value={message} onChange={e =&gt; setMessage(e.target.value)}&gt;&lt;\/textarea&gt;<\/strong>\r\n<strong>                    &lt;ErrorMessage message={errors.message}&gt;&lt;\/ErrorMessage&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>                &lt;div className=\"mb-3\"&gt;<\/strong>\r\n<strong>                    &lt;FormLabel&gt;URL&lt;\/FormLabel&gt;<\/strong>\r\n<strong>                    &lt;input type=\"text\" className=\"w-full md:w-1\/2\" value={url} onChange={e =&gt; setUrl(e.target.value)} \/&gt;<\/strong>\r\n<strong>                    &lt;ErrorMessage message={errors.url}&gt;&lt;\/ErrorMessage&gt;<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>                &lt;button<\/strong>\r\n<strong>                    type=\"button\"<\/strong>\r\n<strong>                    className=\"text-white bg-blue-700 font-medium rounded text-sm px-5 py-2.5 mr-2 mb-2\" onClick={handleSubmit}&gt;<\/strong>\r\n<strong>                    \u9001\u4fe1\u3059\u308b<\/strong>\r\n<strong>                &lt;\/button&gt;<\/strong>\r\n<strong>            &lt;\/div&gt;<\/strong>\r\n<strong>        &lt;\/div&gt;<\/strong>\r\n<strong>    )<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u7279\u5225\u96e3\u3057\u3044\u90e8\u5206\u306f\u7121\u3044\u3067\u3059\u304c\u3001\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u3092\u8003\u616e\u3057\u3066\u300c<strong>\u30a8\u30e9\u30fc\u6642\u306b\u81ea\u52d5\u30b9\u30af\u30ed\u30fc\u30eb\u3057\u3066\u30a8\u30e9\u30fc\u7b87\u6240\u307e\u3067\u79fb\u52d5\u3057\u3066\u304f\u308c\u308b<\/strong>\u300d\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001<code>&lt;textarea&gt; ... &lt;\/textarea&gt;<\/code>\u306b\u306f<code>className<\/code>\u306b<code>block<\/code>\uff08\u30b9\u30bf\u30a4\u30eb\u30b7\u30fc\u30c8\u3067\u8a00\u3046\u3068\u3053\u308d\u306e<code>display: block;<\/code>\uff09\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u3059\u3050\u4e0b\u306b\u9699\u9593\u304c\u3067\u304d\u3066\u3057\u307e\u3046\u305f\u3081\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11060\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_1.png\" alt=\"\" width=\"465\" height=\"274\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_1.png 465w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_1-300x177.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u5b8c\u4e86\u6642\u306e\u30d3\u30e5\u30fc\u3067\u3059\u3002<\/p>\n<p><strong>resources\/js\/Pages\/Contact\/Complete.jsx<\/strong><\/p>\n<pre><strong>export default function Create() {<\/strong>\r\n\r\n<strong>    return (<\/strong>\r\n<strong>        &lt;div className=\"p-5\"&gt;<\/strong>\r\n<strong>            &lt;h1&gt;\u9001\u4fe1\u304c\u5b8c\u4e86\u3057\u307e\u3057\u305f&lt;\/h1&gt;<\/strong>\r\n<strong>            &lt;div className=\"border p-4 bg-gray-50\"&gt;<\/strong>\r\n<strong>                &lt;p&gt;<\/strong>\r\n<strong>                    \u304a\u554f\u3044\u5408\u308f\u305b\u3092\u3044\u305f\u3060\u304d\u307e\u3057\u3066\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3057\u305f\u3002&lt;br \/&gt;<\/strong>\r\n<strong>                    \u3067\u304d\u308b\u3060\u3051\u65e9\u304f\u304a\u8fd4\u4e8b\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u306e\u3067\u3001\u3057\u3070\u3089\u304f\u304a\u5f85\u3061\u304f\u3060\u3055\u3044\u307e\u305b\u3002<\/strong>\r\n<strong>                &lt;\/p&gt;<\/strong>\r\n<strong>            &lt;\/div&gt;<\/strong>\r\n<strong>        &lt;\/div&gt;<\/strong>\r\n<strong>    )<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<h1>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e\u30d3\u30e5\u30fc\u306e\u4e2d\u3067\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u300c<strong>FormLabel<\/strong>\u300d\u3068\u300c<strong>ErrorMessage<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u3053\u308c\u3089\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u5165\u529b\u30dc\u30c3\u30af\u30b9\u306e\u4e0a\u306b\u8868\u793a\u3059\u308b\u300c\u30e9\u30d9\u30eb\u300d\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>\u2193\u2193\u2193\u3000\u3053\u3093\u306a\u30ab\u30f3\u30b8<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11078\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/10\/laravel_react_contact_form_7.png\" alt=\"\" width=\"330\" height=\"86\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/10\/laravel_react_contact_form_7.png 330w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/10\/laravel_react_contact_form_7-300x78.png 300w\" sizes=\"auto, (max-width: 330px) 100vw, 330px\" \/><\/p>\n<p><strong>resources\/js\/Components\/FormLabel.jsx<\/strong><\/p>\n<pre><strong>export default function FormLabel({ required, children }) {<\/strong>\r\n\r\n<strong>    return (<\/strong>\r\n<strong>        &lt;label className=\"font-medium text-xs text-gray-700 mb-2 flex items-center\"&gt;<\/strong>\r\n<strong>            {children}<\/strong>\r\n<strong>            {required &amp;&amp; (<\/strong>\r\n<strong>                &lt;small className=\"bg-red-700 text-white rounded px-1.5 py-0.5 ml-1.5\"&gt;\u5fc5\u9808&lt;\/small&gt;<\/strong>\r\n<strong>            ) || (<\/strong>\r\n<strong>                &lt;small className=\"bg-gray-300 text-gray-700 rounded px-1.5 py-0.5 ml-1.5\"&gt;\u4efb\u610f&lt;\/small&gt;<\/strong>\r\n<strong>            )}<\/strong>\r\n<strong>        &lt;\/label&gt;<\/strong>\r\n<strong>    );<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p><code>required<\/code>\u3092\u4f7f\u3063\u3066\u300c<strong>\u5fc5\u9808<\/strong>\u300d\u3068\u300c<strong>\u4efb\u610f<\/strong>\u300d\u306e\u30e9\u30d9\u30eb\u3092\u5207\u308a\u66ff\u3048\u3066\u3044\u308b\u3068\u3053\u308d\u306b\u6ce8\u76ee\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u3046\u3059\u308b\u3068\u300c<strong>\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u3064\u3051\u308b or \u3064\u3051\u306a\u3044\u3060\u3051<\/strong>\u300d\u3067\u5207\u308a\u66ff\u3048\u304c\u3067\u304d\u308b\u306e\u3067\u4fbf\u5229\u3067\u3059\ud83d\udc4d<\/p>\n<p>\u305d\u3057\u3066\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<p>\u2193\u2193\u2193\u3000\u3053\u3093\u306a\u30ab\u30f3\u30b8<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11077\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/10\/laravel_react_contact_form_8.png\" alt=\"\" width=\"340\" height=\"60\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/10\/laravel_react_contact_form_8.png 340w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/10\/laravel_react_contact_form_8-300x53.png 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/p>\n<p><strong>resources\/js\/Components\/ErrorMessage.jsx<\/strong><\/p>\n<pre><strong>export default function FormLabel({ message }) {<\/strong>\r\n\r\n<strong>    return (<\/strong>\r\n<strong>        &lt;&gt;<\/strong>\r\n<strong>            {message &amp;&amp; (<\/strong>\r\n<strong>                &lt;div className=\"bg-red-600 text-white font-bold p-2 mb-3 rounded-bl rounded-br flex items-center text-sm error-message\"&gt;<\/strong>\r\n<strong>                    &lt;span className=\"text-xs mr-2\"&gt;&amp;#x26A0;&lt;\/span&gt; {message}<\/strong>\r\n<strong>                &lt;\/div&gt;<\/strong>\r\n<strong>            )}<\/strong>\r\n<strong>        &lt;\/&gt;<\/strong>\r\n\r\n<strong>    );<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001\u3082\u3057\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u306a\u3044\u5834\u5408\u306f\u4f55\u3082\u8868\u793a\u3055\u308c\u306a\u3044\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<h1>\u65e5\u672c\u8a9e\u5316\u3059\u308b<\/h1>\n<p>\u3053\u3053\u307e\u3067\u306e\u30b3\u30fc\u30c9\u3067\u554f\u984c\u306a\u304f\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u306f\u6a5f\u80fd\u3057\u307e\u3059\u304c\u3001\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u82f1\u8a9e\u306e\u307e\u307e\u306b\u306a\u3063\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u306f<code>Laravel-Lang<\/code>\u3068<code>Laravel-Lang-Publisher<\/code>\u3092\u4f7f\u3063\u3066\u65e5\u672c\u8a9e\u5316\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>composer require laravel-lang\/publisher laravel-lang\/lang laravel-lang\/attributes --dev<\/strong><\/pre>\n<p>\u203b \u306a\u304a\u3001\u79c1\u306e\u74b0\u5883\u3067\u306f\u30b3\u30f3\u30d5\u30ea\u30af\u30c8\u304c\u767a\u751f\u3057\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u306e\u3067\u3001\u300c\u30d0\u30fc\u30b8\u30e7\u30f3\u3064\u304d\u300d\u3067\u5b9f\u884c\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre><strong>composer require laravel-lang\/publisher:^13.0 laravel-lang\/lang:^10.9 laravel-lang\/attributes:^1.1 --dev<\/strong><\/pre>\n<p>\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3067\u304d\u305f\u3089\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan lang:add ja<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001<code>lang\/ja<\/code>\u30d5\u30a9\u30eb\u30c0\u304c\u4f5c\u6210\u3055\u308c\u3001\u305d\u306e\u4e2d\u306b\u7ffb\u8a33\u30d5\u30a1\u30a4\u30eb\u304c\u683c\u7d0d\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5fd8\u308c\u3066\u306f\u3044\u3051\u306a\u3044\u306e\u304c<code>Laravel<\/code>\u672c\u4f53\u306e\u8a00\u8a9e\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n<p><strong>config\/app.php<\/strong><\/p>\n<pre><strong>'locale' =&gt; 'ja', \/\/ `en` \u304b\u3089\u5909\u66f4<\/strong><\/pre>\n<p>\u203b \u3082\u3057<code>Laravel<\/code>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u3066\u306e\u5834\u5408\u306f\u5408\u308f\u305b\u3066\u4ee5\u4e0b\u306e\u90e8\u5206\u3082\u5909\u66f4\u3057\u3066\u304a\u304f\u3068\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<ul>\n<li>timezone\uff1a Asia\/Tokyo<\/li>\n<li>faker_locale\uff1a ja_JP<\/li>\n<\/ul>\n<p>\u306a\u304a\u3001<code>fallback_locale<\/code>\u306f\u3001<strong>\u30e1\u30a4\u30f3\u306e\u8a00\u8a9e\u304c\u5b58\u5728\u3057\u306a\u304b\u3063\u305f\u3068\u304d\u306e\u4e88\u5099\u8a00\u8a9e<\/strong>\u3067\u3059\u306e\u3067\u3001\u305d\u306e\u307e\u307e<code>en<\/code>\u3067\u3044\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u308c\u3067\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u304a\u75b2\u308c\u69d8\u3067\u3057\u305f\ud83d\ude04\u2728<\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u969b\u306b\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p><code>Vite<\/code>\u3092\u8d77\u52d5\u5f8c\u3001\u300c<strong>http:\/\/******\/contact\/create<\/strong>\u300d\u3078\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a9\u30fc\u30e0\u304c\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n\u5fc5\u9808\u3068\u4efb\u610f\u304c\u5207\u308a\u66ff\u308f\u3063\u3066\u3044\u307e\u3059\u306d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11069\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_2.png\" alt=\"\" width=\"400\" height=\"635\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_2.png 400w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_2-189x300.png 189w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>\u3067\u306f\u3001\u3053\u306e\u30d5\u30a9\u30fc\u30e0\u306b\u3059\u3079\u3066\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u3088\u3046\u306b\u3057\u3066\u9001\u4fe1\u3092\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11068\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_3.png\" alt=\"\" width=\"400\" height=\"820\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_3.png 400w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_3-146x300.png 146w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u3059\u3079\u3066\u306e\u9805\u76ee\u3067\u30a8\u30e9\u30fc\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u6b21\u306f\u9006\u306b\u300c<strong>\u30a8\u30e9\u30fc\u304c\u306a\u3044<\/strong>\u300d\u72b6\u614b\u3067\u9001\u4fe1\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11067\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_4.png\" alt=\"\" width=\"400\" height=\"640\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_4.png 400w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_4-188x300.png 188w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>\u3069\u3046\u306a\u3063\u305f\u3067\u3057\u3087\u3046\u304b\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11066\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_5.png\" alt=\"\" width=\"620\" height=\"130\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_5.png 620w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_5-300x63.png 300w\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u5b8c\u4e86\u30da\u30fc\u30b8\u304c\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u30e1\u30fc\u30eb\u306f\u9001\u4fe1\u3055\u308c\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\uff1f\uff1f<\/p>\n<p>\u305f\u306e\u3080\u305e\uff01\uff01\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-11065\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_6.png\" alt=\"\" width=\"406\" height=\"470\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_6.png 406w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2022\/09\/laravel_react_contact_form_6-259x300.png 259w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\u3053\u3061\u3089\u3082\u3046\u307e\u304f\u5165\u529b\u5185\u5bb9\u304c\u9001\u4fe1\u3055\u308c\u3066\u307e\u3057\u305f\u3002<\/p>\n<p>\u3059\u3079\u3066\u6210\u529f\u3067\u3059\ud83d\ude04\u2728<\/p>\n<h1>\u30c7\u30e2\u30da\u30fc\u30b8\u3092\u3064\u304f\u308a\u307e\u3057\u305f<\/h1>\n<p>\u305b\u3063\u304b\u304f\u306a\u306e\u3067\u3001\u30c7\u30e2\u30da\u30fc\u30b8\u3092\u3064\u304f\u308a\u307e\u3057\u305f\u3002<br \/>\n\u4ee5\u4e0b\u304b\u3089\u8a66\u305b\u307e\u3059\u306e\u3067\u3001\u3088\u308d\u3057\u3051\u308c\u3070\u4f53\u9a13\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\ud83d\udcdd <a href=\"https:\/\/demo-laravel9x-vite.capilano-fw.com\/contact\/create\" target=\"_blank\" rel=\"noopener\">\u30c7\u30e2\u30da\u30fc\u30b8<\/a><\/p>\n<h1>\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h1>\n<p>\u4eca\u56de\u958b\u767a\u3057\u305f\u5185\u5bb9\u306f\u300c<strong>\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0<\/strong>\u300d\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u672c\u6765\u306f\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u4eca\u56de\u306f\u300c\u3088\u308a\u30e2\u30c0\u30f3\u306a\u300d\u30b3\u30fc\u30c9\u3092\u5fc3\u304c\u3051\u3066\u958b\u767a\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3082\u3057\u4eca\u5f8c\u3001\u5fa1\u793e\u306e\u958b\u767a\u74b0\u5883\u3092\u5237\u65b0\u3055\u308c\u305f\u3044\u306a\u3069\u3068\u3044\u3063\u305f\u3054\u5e0c\u671b\u304c\u3054\u3056\u3044\u307e\u3057\u305f\u3089\u3001\u3044\u3064\u3067\u3082\u304a\u6c17\u8efd\u306b\u3054\u9023\u7d61\u304f\u3060\u3055\u3044\u3002\u304d\u3063\u3068\u304a\u529b\u306b\u306a\u308c\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u304a\u5f85\u3061\u3057\u3066\u304a\u308a\u307e\u3059\u3002\ud83d\ude04\u2728<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u300c<strong>Laravel + React<\/strong>\u300d\u3067\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u300c<strong>\u30b7\u30f3\u30d7\u30eb\u306a\u30c6\u30fc\u30de \uff0b \u5c11\u3057\u9577\u3044\u30b3\u30fc\u30c9<\/strong>\u300d\u306e\u30bf\u30c3\u30b0\u3067\u304a\u5c4a\u3051\u3057\u307e\u3057\u305f\u304c\u3044\u304b\u304c\u3060\u3063\u305f\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u500b\u4eba\u7684\u306a\u611f\u60f3\u3068\u3057\u3066\u306f\u3001\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u3068\u3044\u3046\u3042\u308a\u3075\u308c\u305f\u958b\u767a\u3067\u3042\u308b\u306b\u3082\u95a2\u308f\u3089\u305a\u3001\u7d50\u69cb\u3044\u308d\u3044\u308d\u306a\u77e5\u8b58\u304c\u5fc5\u8981\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u306e\u3067\u3001\u521d\u5b66\u8005\u306e\u52c9\u5f37\u306e\u305f\u3081\u306b\u3082\u3044\u3044\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u7814\u7a76\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9470 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png\" alt=\"\" width=\"294\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13.png 294w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/08\/no_13-276x300.png 276w\" sizes=\"auto, (max-width: 294px) 100vw, 294px\" \/>\u300c\u30d3\u30fc\u30eb\u304c\u5024\u4e0a\u304c\u308a\u3059\u308b\u2757\u2753<br \/>\n\u3093\u30fc\u2026\u5909\u308f\u3089\u305a\u98f2\u3080\u3088\ud83c\udf7a\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593\u00a0Laravel + React \u3067\u30ea\u30a2\u30eb\u30bf\u30a4\u30e0\u30fb\u30c1\u30e3\u30c3\u30c8\u3092\u3064\u304f\u308b \u3068\u3044\u3046\u8a18\u4e8b\u304c\u601d\u3044\u306e\u307b\u304b\u591a\u304f\u8aad\u3093\u3067\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002\uff08\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u2757\uff09  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=11056\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel + React \u3067\u304a\u554f\u3044\u5408\u308f\u305b\u30d5\u30a9\u30fc\u30e0\u3092\u3064\u304f\u308b\uff08Enum\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3001\u65e5\u672c\u8a9e\u5316\u3082\uff01\uff09&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":11074,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[247,3,118,249,248],"tags":[],"class_list":["post-11056","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-inertia-js","category-laravel","category-react-js","category-tailwind-css","category-vite"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11056"}],"version-history":[{"count":16,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11056\/revisions"}],"predecessor-version":[{"id":11260,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/11056\/revisions\/11260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/11074"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}