{"id":7369,"date":"2020-05-25T15:00:31","date_gmt":"2020-05-25T06:00:31","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=7369"},"modified":"2020-05-08T20:15:06","modified_gmt":"2020-05-08T11:15:06","slug":"laravel%e3%81%a7%e3%83%95%e3%82%a9%e3%83%ad%e3%83%bc%e6%a9%9f%e8%83%bd%e3%82%92%e3%81%a4%e3%81%8f%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=7369","title":{"rendered":"Laravel\u3067\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4ee5\u524d\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=6825\">\u3010wordpress\u3011\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3057\u3067Twitter\u306b\u81ea\u52d5\u6295\u7a3f\u3059\u308b<\/a>\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3067\u3082\u66f8\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3092<code>Twitter<\/code>\u3068\u9023\u643a\u3055\u305b\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304b\u3089\u7d04\uff11\u30f5\u6708\u304c\u7d4c\u3061\u307e\u3057\u305f\u3002<\/p>\n<p>\u4e2d\u306b\u306f\u3053\u3093\u306a\u30d6\u30ed\u30b0\u306e<code>Twitter<\/code>\u306a\u306e\u306b<strong>\u30d5\u30a9\u30ed\u30fc\u3092\u3057\u3066\u3044\u305f\u3060\u304f\u65b9\u3082\u3044\u3089\u3063\u3057\u3083\u3063\u3066\u30db\u30f3\u30c8\u3042\u308a\u304c\u305f\u3044\u9650\u308a\u3067\u3059\ud83d\ude0a\u2728<\/strong><\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u3093\u306a\u3053\u3068\u3092\u8003\u3048\u3066\u3044\u308b\u3068\u3072\u3068\u3064\u4f5c\u3063\u3066\u307f\u305f\u3044\u6a5f\u80fd\u304c\u601d\u3044\u6d6e\u304b\u3093\u3067\u304d\u307e\u3057\u305f\u3002\u305d\u308c\u304c\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">Twitter\u307f\u305f\u3044\u306a\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u2757<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u6a5f\u80fd\u3082\u4eca\u3067\u306f\u5f53\u305f\u308a\u524d\u3067\u3059\u304c\u3001\u767b\u5834\u3057\u305f\u3068\u304d\u306f\u3068\u3066\u3082\u753b\u671f\u7684\u3060\u3063\u305f\u3093\u3058\u3083\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f<code>Laravel<\/code>\u3092\u4f7f\u3063\u3066\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u3092\u5b9f\u88c5\u3057\u3001\u3055\u3089\u306b<strong>\u30d5\u30a9\u30ed\u30fc\u3055\u308c\u3066\u3044\u308b\u4eba\u304c\u4f55\u304b\u3092\u6295\u7a3f\u3057\u305f\u3089\u305d\u306e\u4eba\u305f\u3061\u306b\u30e1\u30fc\u30eb\u3067\u304a\u77e5\u3089\u305b\u3059\u308b<\/strong>\u3068\u3044\u3046\u6a5f\u80fd\u3092\u3064\u304f\u3063\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u697d\u3057\u307f\u306a\u304c\u3089\u3084\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u2757<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3344 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22.png\" alt=\"\" width=\"320\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22.png 320w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-150x150.png 150w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-300x300.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_22-100x100.png 100w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/p>\n<p style=\"text-align: center;\">\u300cFF\u5916\u3063\u3066\u3001\u30d5\u30a9\u30ed\u30fc\uff06\u30d5\u30a9\u30ed\u30ef\u30fc<br \/>\n\u306e\u7565\u3060\u3063\u305f\u3093\u3067\u3059\u306d\u3002\u30b2\u30fc\u30e0\u95a2\u4fc2\u306a\u304b\u3063\u305f\ud83d\ude02\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 7.x<\/p>\n<h1>\u524d\u63d0\u3068\u3057\u3066<\/h1>\n<p>\u4eca\u56de\u3082<code>Laravel<\/code>\u306b\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u3066\u3001\u3055\u3089\u306b\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u524d\u63d0\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3082\u3057\u307e\u3060\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u65b9\u306f\u3001\u300c<a href=\"https:\/\/blog.capilano-fw.com\/?p=4576\">Laravel6.x\u4ee5\u964d\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u306f\u3053\u3093\u306a\u30ab\u30f3\u30b8\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7293\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_arrival_notification_1.png\" alt=\"\" width=\"527\" height=\"372\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_arrival_notification_1.png 527w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_arrival_notification_1-300x212.png 300w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><\/p>\n<h1>\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u4eca\u56de\u5fc5\u8981\u306b\u306a\u308b\u4ee5\u4e0b\uff12\u3064\u306e\u30e2\u30c7\u30eb\uff06\u30c6\u30fc\u30d6\u30eb\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>Follwing\uff1a \u8ab0\u304c\u8ab0\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b\u304b\u3092\u7ba1\u7406\u3059\u308b<\/li>\n<li>Post\uff1a \u3053\u3053\u306b\u6295\u7a3f\u3055\u308c\u305f\u3089\u30d5\u30a9\u30ed\u30ef\u30fc\u306b\u304a\u77e5\u3089\u305b\u30e1\u30fc\u30eb\u3092\u9001\u4fe1<\/li>\n<\/ul>\n<p>\u3067\u306f\u3072\u3068\u3064\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u306f<code>Follwing<\/code>\u3067\u3059\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:model Following -m<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30e2\u30c7\u30eb\u3068\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\uff12\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u307e\u305a\u30e2\u30c7\u30eb\u306b<code>User<\/code>\u30e2\u30c7\u30eb\u3068\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p><strong><code>\/app\/Following.php<\/code><\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass Following extends Model\r\n{\r\n    \/\/ \u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\r\n    <strong>public function user() { \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n\r\n<strong>        return $this-&gt;belongsTo(\\App\\User::class, 'user_id', 'id');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p><strong><code>\/database\/migrations\/****_**_**_******_create_followings_table.php<\/code><\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\npublic function up()\r\n{\r\n    Schema::create('followings', function (Blueprint $table) {\r\n        $table-&gt;id();\r\n        <strong>$table-&gt;unsignedBigInteger('user_id')-&gt;comment('\u30e6\u30fc\u30b6\u30fcID'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n<strong>        $table-&gt;unsignedBigInteger('following_user_id')-&gt;comment('\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u3044\u308b\u4eba\u306eID'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n        $table-&gt;timestamps();\r\n\r\n        <strong>$table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n<strong>        $table-&gt;foreign('following_user_id')-&gt;references('id')-&gt;on('users'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n    });\r\n}\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3067\u306f\u3001\u7d9a\u3044\u3066<code>Post<\/code>\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<strong><code><\/code><\/strong><\/p>\n<pre><strong>php artisan make:model Post -m<\/strong><\/pre>\n<p>\u540c\u3058\u304f\u30e2\u30c7\u30eb\u3068\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u3053\u3061\u3089\u306b\u3082<code>User<\/code>\u30e2\u30c7\u30eb\u3068\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><strong><code>\/app\/Post.php<\/code><\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass Post extends Model\r\n{\r\n    \/\/ \u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\r\n    <strong>public function user() { \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n\r\n<strong>        return $this-&gt;belongsTo(\\App\\User::class, 'user_id', 'id');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u6b21\u306b\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p><strong><code>\/database\/migrations\/****_**_**_******_create_posts_table.php<\/code><\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\npublic function up()\r\n{\r\n    Schema::create('posts', function (Blueprint $table) {\r\n        $table-&gt;id();\r\n        <strong>$table-&gt;unsignedBigInteger('user_id')-&gt;comment('\u30e6\u30fc\u30b6\u30fcID'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n<strong>        $table-&gt;string('title')-&gt;comment('\u30bf\u30a4\u30c8\u30eb'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n<strong>        $table-&gt;string('description')-&gt;comment('\u5185\u5bb9'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n        $table-&gt;timestamps();\r\n\r\n        <strong>$table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users'); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n    });\r\n}\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30c6\u30fc\u30d6\u30eb\u3092\u3064\u304f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u5b9f\u969b\u306e\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7370\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_1.png\" alt=\"\" width=\"452\" height=\"252\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_1.png 452w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_1-300x167.png 300w\" sizes=\"auto, (max-width: 452px) 100vw, 452px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7371\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_2.png\" alt=\"\" width=\"346\" height=\"275\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_2.png 346w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_2-300x238.png 300w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/p>\n<h1>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001<code>follwings<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u30c6\u30b9\u30c8\u3068\u3057\u3066\u4f7f\u3046\u4ee5\u4e0b\u306e\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u592a\u90ce\u3055\u3093\uff08id: 1\uff09\u306f\u3001\u4e09\u90ce\u3055\u3093\uff08id: 3\uff09\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b<\/li>\n<li>\u6b21\u90ce\u3055\u3093\uff08id: 2\uff09\u3082\u3001\u4e09\u90ce\u3055\u3093\uff08id: 3\uff09\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b<\/li>\n<li>\u4e09\u90ce\u3055\u3093\uff08id: 3\uff09\u306f\u3001\u592a\u90ce\u3055\u3093\uff08id: 1\uff09\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001<\/p>\n<ul>\n<li>\u4e09\u90ce\u3055\u3093\u304c\u6295\u7a3f\u3059\u308b\u3068\u3001\u592a\u90ce\u3055\u3093\u3068\u6b21\u90ce\u3055\u3093\u306b\u30e1\u30fc\u30eb\u901a\u77e5<\/li>\n<li>\u592a\u90ce\u3055\u3093\u304c\u6295\u7a3f\u3059\u308b\u3068\u3001\u4e09\u90ce\u3055\u3093\u3060\u3051\u306b\u30e1\u30fc\u30eb\u901a\u77e5<\/li>\n<\/ul>\n<p>\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3067\u306f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067<code>Seeder<\/code>\u30d5\u30a1\u30a4\u30eb\u3092\u3064\u304f\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan make:seed FollowingsTableSeeder<\/strong><\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u305f\u3089\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong><code>\/database\/seeds\/FollowingsTableSeeder.php<\/code><\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\npublic function run()\r\n{\r\n    <strong>$following_data = [<\/strong>\r\n<strong>        ['user_id' =&gt; 1, 'following_user_id' =&gt; 3], \/\/ \u592a\u90ce\u3055\u3093\uff08ID: 1\uff09\u306f\u4e09\u90ce\u3055\u3093\uff08ID: 3\uff09\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b<\/strong>\r\n<strong>        ['user_id' =&gt; 2, 'following_user_id' =&gt; 3], \/\/ \u6b21\u90ce\u3055\u3093\uff08ID: 2\uff09\u3082\u4e09\u90ce\u3055\u3093\uff08ID: 3\uff09\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b<\/strong>\r\n<strong>        ['user_id' =&gt; 3, 'following_user_id' =&gt; 1], \/\/ \u4e09\u90ce\u3055\u3093\uff08ID: 3\uff09\u306f\u3001\u592a\u90ce\u3055\u3093\uff08ID: 1\uff09\u3092\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u308b<\/strong>\r\n<strong>    ];<\/strong>\r\n\r\n<strong>    foreach($following_data as $following_values) {<\/strong>\r\n\r\n<strong>        $following = new \\App\\Following();<\/strong>\r\n<strong>        $following-&gt;user_id = $following_values['user_id'];<\/strong>\r\n<strong>        $following-&gt;following_user_id = $following_values['following_user_id'];<\/strong>\r\n<strong>        $following-&gt;save();<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067DB\u3092\u521d\u671f\u5316\u3057\u3064\u3064\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3082\u8ffd\u52a0\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7374\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_3.png\" alt=\"\" width=\"561\" height=\"316\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_3.png 561w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_3-300x169.png 300w\" sizes=\"auto, (max-width: 561px) 100vw, 561px\" \/><\/p>\n<h1>\u30eb\u30fc\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3053\u3053\u3067\u3001\u4eca\u56de\u306f\u5b9f\u969b\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u305b\u3093\u304c\u3001<code>posts<\/code>\u7528\u306b\u30eb\u30fc\u30c8\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u304a\u77e5\u3089\u305b\u30e1\u30fc\u30eb\u306e\u4e2d\u3067\u30ea\u30f3\u30af\u306eURL\u3068\u3057\u3066\u4f7f\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong><code>\/routes\/web.php<\/code><\/strong><\/p>\n<pre><strong>Route::get('post\/{post}', function(\\App\\Post $post){<\/strong>\r\n\r\n<strong>    return $post;<\/strong>\r\n\r\n<strong>})-&gt;name('post.show');<\/strong><\/pre>\n<h1>\u30e1\u30fc\u30eb\u9001\u4fe1\u90e8\u5206\u3092\u3064\u304f\u308b<\/h1>\n<p>\u6b21\u306e\u9805\u76ee\u3067\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u3001\u5148\u306b\u304a\u77e5\u3089\u305b\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u3063\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2>Mailable\u3092\u3064\u304f\u308b<\/h2>\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 PostCreated<\/strong><\/pre>\n<p>\u3059\u308b\u3068<code>Mailable<\/code>\u3068\u547c\u3070\u308c\u308b<code>Laravel<\/code>\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong><code>\/app\/Mail\/PostCreated.php<\/code><\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Mail;\r\n\r\nuse App\\Post;\r\nuse App\\User;\r\nuse Illuminate\\Bus\\Queueable;\r\nuse Illuminate\\Contracts\\Queue\\ShouldQueue;\r\nuse Illuminate\\Mail\\Mailable;\r\nuse Illuminate\\Queue\\SerializesModels;\r\n\r\nclass PostCreated extends Mailable\r\n{\r\n    use Queueable, SerializesModels;\r\n\r\n    <strong>private $post, $user;<\/strong>\r\n\r\n    \/**\r\n     * Create a new message instance.\r\n     *\r\n     * @return void\r\n     *\/\r\n    <strong>public function __construct(Post $post, User $user)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $this-&gt;post = $post;<\/strong>\r\n<strong>        $this-&gt;user = $user;<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n    \/**\r\n     * Build the message.\r\n     *\r\n     * @return $this\r\n     *\/\r\n    <strong>public function build()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        return $this-&gt;subject($this-&gt;post-&gt;user-&gt;name .'\u3055\u3093\u304c\u65b0\u3057\u3044\u6295\u7a3f\u3092\u3057\u307e\u3057\u305f')<\/strong>\r\n<strong>            -&gt;from('from@example.com')<\/strong>\r\n<strong>            -&gt;text('emails.post_created')<\/strong>\r\n<strong>            -&gt;with([<\/strong>\r\n<strong>                'post' =&gt; $this-&gt;post,<\/strong>\r\n<strong>                'user' =&gt; $this-&gt;user<\/strong>\r\n<strong>            ]); \/\/ $post, $user\u3092\u30d3\u30e5\u30fc\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b<\/strong>\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u91cd\u8981\u306a\u306e\u304c<code>build()<\/code>\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u3053\u3053\u3067\u306f\u4ee5\u4e0b\u306e\u30c7\u30fc\u30bf\u3092\u30bb\u30c3\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>subject(): \u30e1\u30fc\u30eb\u306e\u4ef6\u540d<\/li>\n<li>from(): \u9001\u4fe1\u5143<\/li>\n<li>text(): \u30e1\u30fc\u30eb\u6587\u9762\u306e\u30d3\u30e5\u30fc\u3092\u6307\u5b9a<\/li>\n<li>with(): \u30d3\u30e5\u30fc\u5185\u306b\u30c7\u30fc\u30bf\u3092\u9001\u308b<\/li>\n<\/ul>\n<h2>\u30e1\u30fc\u30eb\u306e\u6587\u9762\uff08\u30d3\u30e5\u30fc\uff09\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u9001\u4fe1\u3055\u308c\u308b\u30e1\u30fc\u30eb\u6587\u9762\u3092\u30d3\u30e5\u30fc\u3067\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p><strong><code>\/resources\/views\/emails\/post_created.blade.php<\/code><\/strong><\/p>\n<pre><strong>{{ $user-&gt;name }}<\/strong> \u3055\u3093\u3078\r\n\r\n<strong>{{ $post-&gt;user-&gt;name }}<\/strong> \u3055\u3093\u304c\u65b0\u3057\u3044\u6295\u7a3f\u3092\u3057\u307e\u3057\u305f\u3002\r\n\r\n\u3010\u6295\u7a3f\u3055\u308c\u305f\u30da\u30fc\u30b8\u3011 <strong>{{ route('post.show', $post-&gt;id) }}<\/strong>\r\n\r\n-------------------------------\r\n\r\nConsole dot Log\r\nhttps:\/\/blog.capilano-fw.com<\/pre>\n<p>\u306a\u304a\u3001\u5b9f\u969b\u306b\u9001\u4fe1\u3055\u308c\u308b\u30c6\u30ad\u30b9\u30c8\u306f\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3010\u4f8b\u3011<\/p>\n<pre>\u592a\u90ce \u3055\u3093\u3078\r\n\r\n\u4e09\u90ce \u3055\u3093\u304c\u65b0\u3057\u3044\u6295\u7a3f\u3092\u3057\u307e\u3057\u305f\u3002\r\n\r\n\u3010\u6295\u7a3f\u3055\u308c\u305f\u30da\u30fc\u30b8\u3011 http:\/\/*****\/post\/29\r\n\r\n-------------------------------\r\n\r\nConsole dot Log\r\nhttps:\/\/blog.capilano-fw.com<\/pre>\n<h1>\u30a4\u30d9\u30f3\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p>\u7d9a\u3044\u3066\u3001<code>posts<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3089\u304a\u77e5\u3089\u305b\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\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:event PostCreated<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30a4\u30d9\u30f3\u30c8\u30fb\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong><code>\/app\/Events\/PostCreated.php<\/code><\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\n<strong>public function __construct(Post $post)<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    $followings = \\App\\Following::with('user')<\/strong>\r\n<strong>        -&gt;where('following_user_id', $post-&gt;user_id)<\/strong>\r\n<strong>        -&gt;get();<\/strong>\r\n\r\n<strong>    foreach($followings as $following) {<\/strong>\r\n\r\n<strong>        $user = $following-&gt;user;<\/strong>\r\n<strong>        \\Mail::to($user)-&gt;send(new \\App\\Mail\\PostCreated($post, $user)); \/\/ \u30e1\u30fc\u30eb\u9001\u4fe1<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n<strong>}<\/strong>\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<p>\u3067\u306f\u3001<code>PostCreated<\/code>\u30a4\u30d9\u30f3\u30c8\u3092\u30e2\u30c7\u30eb\u306b\u30bb\u30c3\u30c8\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\n<strong>use App\\Events\\PostCreated; \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass Post extends Model\r\n{\r\n    <strong>protected $dispatchesEvents = [ \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n<strong>        'created' =&gt; PostCreated::class<\/strong>\r\n<strong>    ];<\/strong>\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u300c\u304a\u77e5\u3089\u305b\u30e1\u30fc\u30eb\u300d\u304c\u9001\u4fe1\u3055\u308c\u308b\u304b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u307e\u305a\u6b21\u306e\u30eb\u30fc\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong><code>\/routes\/web.php<\/code><\/strong><\/p>\n<pre><strong>Route::get('following\/test', function(){\r\n\r\n    \/\/ \u4e09\u90ce\u3055\u3093\u304c\u6295\u7a3f\uff08\u592a\u90ce\uff06\u6b21\u90ce\u3078\u30e1\u30fc\u30eb\u901a\u77e5\u3067\u304d\u308b\uff1f\uff1f\uff09\r\n    $post = new \\App\\Post();\r\n    $post-&gt;user_id = 3; \/\/ \u4e09\u90ce\u3055\u3093\u306eID\r\n    $post-&gt;title = '\u30c6\u30b9\u30c8\u30bf\u30a4\u30c8\u30eb by \u4e09\u90ce';\r\n    $post-&gt;description = '\u30c6\u30b9\u30c8\u6587\u7ae0 by \u4e09\u90ce';\r\n    $post-&gt;save();\r\n\r\n    \/\/ \u592a\u90ce\u3055\u3093\u304c\u6295\u7a3f\uff08\u4e09\u90ce\u3078\u30e1\u30fc\u30eb\u901a\u77e5\u3067\u304d\u308b\uff1f\uff1f\uff09\r\n    $post = new \\App\\Post();\r\n    $post-&gt;user_id = 1; \/\/ \u592a\u90ce\u3055\u3093\u306eID\r\n    $post-&gt;title = '\u30c6\u30b9\u30c8\u30bf\u30a4\u30c8\u30eb by \u592a\u90ce';\r\n    $post-&gt;description = '\u30c6\u30b9\u30c8\u6587\u7ae0 by \u592a\u90ce';\r\n    $post-&gt;save();\r\n\r\n});<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u300c<strong>http:\/\/*****\/following\/test<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b\u306a\u304a\u3001\u4eca\u56de\u306f\u300c<a href=\"https:\/\/mailcatcher.me\/\" target=\"_blank\" rel=\"noopener noreferrer\">mailcatcher<\/a>\u300d\u3092\u4f7f\u3063\u3066\u30c6\u30b9\u30c8\u3057\u307e\u3059\u304c\u3001<code>.env<\/code>\u306e<code>MAIL_DRIVER<\/code>\u3092<code>log<\/code>\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u3082\u8a66\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u3001\u30e1\u30fc\u30eb\u304c\uff13\u901a\u9001\u4fe1\u3055\u308c\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\n\u4e2d\u8eab\u306f\u305d\u308c\u305e\u308c\u4ee5\u4e0b\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7375\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_4.png\" alt=\"\" width=\"364\" height=\"260\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_4.png 364w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_4-300x214.png 300w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7376\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_5.png\" alt=\"\" width=\"365\" height=\"260\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_5.png 365w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_5-300x214.png 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7377\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_6.png\" alt=\"\" width=\"365\" height=\"260\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_6.png 365w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/05\/laravel_following_6-300x214.png 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<h1>\u6559\u6750\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b<\/h1>\n<p>\u4eca\u56de\u5b9f\u969b\u306b\u958b\u767a\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u4ee5\u4e0b\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=7379&amp;tmstv=1777538152\" rel=\"nofollow\" id=\"download-link-7379\" data-redirect=\"false\" >\n\tLaravel\u3067\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\n\n<p>\u203b\u305f\u3060\u3057\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u306a\u3069\u306f\u3054\u81ea\u8eab\u3067\u884c\u3063\u3066\u3044\u305f\u3060\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Laravel<\/code>\u3067<code>Twitter<\/code>\u306e\u3088\u3046\u306a\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u3092\u3064\u304f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u306f<code>Twitter<\/code>\u3060\u3051\u3058\u3083\u306a\u304f\u3001\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u30b5\u30a4\u30c8\u3067\u306f\u3060\u3044\u305f\u3044\u63a1\u7528\u3055\u308c\u3066\u3044\u308b\u3068\u601d\u3046\u306e\u3067\u3001<strong>\u30e6\u30fc\u30b6\u30fc\u306e\u3084\u308a\u53d6\u308a\u304c\u5fc5\u8981\u306a\u30b5\u30a4\u30c8\u306b\u306f\u3082\u3063\u3066\u3053\u3044\u306e\u6a5f\u80fd\u3060\u3068\u601d\u3044\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u3084\u3063\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6067 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19.png\" alt=\"\" width=\"314\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19.png 314w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_19-294x300.png 294w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u3082\u3061\u308d\u3093\u30d5\u30a9\u30ed\u30fc\u3082\u3067\u3059\u304c\u3001<br \/>\n\u30c4\u30a4\u30fc\u30c8\u306b\u30cf\u30fc\u30c8\u304c\u3064\u3044\u305f\u308a\u3059\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\u3088\u306d\ud83d\ude0a\u2728\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u4ee5\u524d\u300c\u3010wordpress\u3011\u30d7\u30e9\u30b0\u30a4\u30f3\u306a\u3057\u3067Twitter\u306b\u81ea\u52d5\u6295\u7a3f\u3059\u308b\u300d\u3068\u3044\u3046\u8a18\u4e8b\u3067\u3082\u66f8\u3044\u305f\u306e\u3067\u3059\u304c\u3001\u3053\u306e\u30d6\u30ed\u30b0\u3092Twitter\u3068\u9023\u643a\u3055\u305b\u308b\u3088\u3046\u306b\u306a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=7369\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel\u3067\u30d5\u30a9\u30ed\u30fc\u6a5f\u80fd\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":7384,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[192],"class_list":["post-7369","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-twitter"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7369","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=7369"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7369\/revisions"}],"predecessor-version":[{"id":7385,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7369\/revisions\/7385"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/7384"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}