{"id":7560,"date":"2020-07-20T15:00:07","date_gmt":"2020-07-20T06:00:07","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=7560"},"modified":"2020-07-13T02:54:56","modified_gmt":"2020-07-12T17:54:56","slug":"laravel%e3%81%a7%e3%80%8c%e3%81%93%e3%81%ae%e5%95%86%e5%93%81%e3%82%92%e8%a6%8b%e3%81%9f%e4%ba%ba%e3%81%af%e3%81%93%e3%81%a1%e3%82%89%e3%81%ae%e5%95%86%e5%93%81%e3%82%82%e8%a6%8b%e3%81%a6%e3%81%84","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=7560","title":{"rendered":"Laravel\u3067\u300c\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u666e\u6bb5\u304b\u3089\u79c1\u306f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u304a\u8cb7\u3044\u7269\u3092\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001<code>Amazon<\/code>\u306a\u3069\u3067\u898b\u304b\u3051\u308b<strong>\u3042\u308b\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u3044\u3064\u3082\u6c17\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305d\u306e\u6a5f\u80fd\u306f\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u300c\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059\u300d<\/strong><\/p>\n<p>\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3084\u306f\u308a<strong>\u540c\u3058\u5546\u54c1\u3092\u898b\u305f\u4ed6\u306e\u4eba\u305f\u3061\u306f\u3001\u597d\u307f\u304c\u4f3c\u3066\u308b<\/strong>\u308f\u3051\u3067\u3001\u3088\u304f\u300c\u304a\u3063\u3001\u5206\u304b\u3063\u3066\u308b\u306d\u301c\u266a\u300d\u306a\u3093\u3066\u3044\u3044\u306a\u304c\u3089\u601d\u308f\u305a\u30dd\u30c1\u3063\u3066\u3057\u307e\u3044\u307e\u3059\ud83d\ude02<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u3053\u306e\u300c\u304a\u3059\u3059\u3081\u7d39\u4ecb\u6a5f\u80fd\u300d\u3092<code>Laravel<\/code>\u3067\u3064\u304f\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u305f\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<br \/>\n\uff08\u6700\u5f8c\u306b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u4e00\u5f0f\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3067\u304d\u307e\u3059\u3088\ud83d\udc4d\uff09<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6071 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_8.png\" alt=\"\" width=\"216\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_8.png 216w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_8-203x300.png 203w\" sizes=\"auto, (max-width: 216px) 100vw, 216px\" \/>\u300c\u9f3b\u3046\u304c\u3044\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3001<br \/>\n\u4f53\u8abf\u826f\u304f\u306a\u308a\u307e\u3057\u305f\ud83d\ude0a\u300d<\/p>\n<h1>\u3069\u3046\u3084\u3063\u3066\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u63a2\u3059\u304b\uff1f<\/h1>\n<p>\u300c<strong>\u3042\u308b\u5546\u54c1\u3092\u898b\u305f\u4eba\u305f\u3061<\/strong>\u300d\u304c\u30c1\u30a7\u30c3\u30af\u3057\u305f\u4ed6\u306e\u5546\u54c1\u3092\u62bd\u51fa\u3059\u308b\u306b\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u3092\u3068\u308a\u307e\u3059\u3002<\/p>\n<ol>\n<li>\u3042\u308b\u5546\u54c1\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u4eba\u305f\u3061\u306eIP\u30a2\u30c9\u30ec\u30b9\u3092\u53d6\u5f97<\/li>\n<li>\u305d\u306eIP\u30a2\u30c9\u30ec\u30b9\u304c\u30a2\u30af\u30bb\u30b9\u3057\u305f\u4ed6\u306e\u5546\u54c1\u3092\u53d6\u5f97<\/li>\n<li>\u5546\u54c1\u3054\u3068\u306b\u30a2\u30af\u30bb\u30b9\u56de\u6570\uff08\u95a2\u9023\u5ea6\uff09\u3092\u96c6\u8a08\u3057\u3066\u30c7\u30fc\u30bf\u4fdd\u5b58<\/li>\n<\/ol>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306e\u4f5c\u696d\u306b\u3044\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<h1>\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308b<\/h1>\n<p>\u307e\u305a\u306f\u3001\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\uff08\u2252DB\u30c6\u30fc\u30d6\u30eb\u8a2d\u8a08\u66f8\uff09\u3092\u3064\u304f\u308a\u307e\u3059\u304c\u3001\u5168\u90e8\u3067\uff13\u30bb\u30c3\u30c8\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u3072\u3068\u3064\u305a\u3064\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5546\u54c1<\/li>\n<li>\u5546\u54c1\u3078\u306e\u30a2\u30af\u30bb\u30b9<\/li>\n<li>\u304a\u3059\u3059\u3081\u5546\u54c1<\/li>\n<\/ul>\n<h2>\u5546\u54c1<\/h2>\n<p>\u5546\u54c1\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306e\u3082\u306e\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 Product -m<\/strong><\/pre>\n<p>\u30e2\u30c7\u30eb\u3068\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><code>\/app\/Product.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass Product extends Model\r\n{\r\n    \/\/ \ud83d\udc47 \u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\r\n    <strong>public function accesses() {<\/strong>\r\n\r\n<strong>        return $this-&gt;hasMany('App\\ProductAccess', 'product_id', 'id');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function recommendations() {<\/strong>\r\n\r\n<strong>        return $this-&gt;hasMany('App\\ProductRecommendation', 'original_product_id', 'id')<\/strong>\r\n<strong>            -&gt;orderBy('access_count', 'desc');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3053\u306e\u4e2d\u306e<code>accesses()<\/code>\u306f\u3001\u5f8c\u3067\u3064\u304f\u308b<code>product_accesses<\/code>\u30c6\u30fc\u30d6\u30eb\u3068\u306e\u3001\u305d\u3057\u3066<code>recommendations()<\/code>\u306f<code>product_recommendations<\/code>\u3068\u306e\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3067\u3001<strong>\u3069\u3061\u3089\u3082\u300c\uff11\uff1a\u591a\u300d\u306e\u95a2\u4fc2\u306b\u306a\u308a\u307e\u3059\u3002<\/strong><\/p>\n<p>\u305d\u3057\u3066\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p><code>\/database\/migrations\/****_**_**_******_create_products_table.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass CreateProductsTable extends Migration\r\n{\r\n    <strong>public function up()\r\n    {\r\n\u00a0       Schema::create('products', function (Blueprint $table) {<\/strong>\r\n<strong>            $table-&gt;id();<\/strong>\r\n<strong>            $table-&gt;string('name')-&gt;comment('\u5546\u54c1\u540d');<\/strong>\r\n<strong>            $table-&gt;string('image_url')-&gt;nullable()-&gt;comment('\u753b\u50cfURL');<\/strong>\r\n<strong>            $table-&gt;dateTime('recommendation_updated_at')-&gt;nullable()-&gt;comment('\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3057\u305f\u65e5\u6642');<\/strong>\r\n<strong>            $table-&gt;timestamps();<\/strong>\r\n<strong>        });\r\n    }<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n}<\/pre>\n<p><code>recommendation_updated_at<\/code>\u306f\u3001\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u96c6\u8a08\u3057\u305f\u65e5\u6642\u304c\u4fdd\u5b58\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u3001\u3053\u306e\u5185\u5bb9\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066<strong>\uff13\u65e5\u3054\u3068\u306b\u304a\u3059\u3059\u3081\u30c7\u30fc\u30bf\u3092\u81ea\u52d5\u66f4\u65b0\u3057\u305f\u308a\u3057\u307e\u3059\u3002<\/strong>\uff08\u5f8c\u307b\u3069\u3054\u7d39\u4ecb\u3057\u307e\u3059\uff09<\/p>\n<h2>\u5546\u54c1\u3078\u306e\u30a2\u30af\u30bb\u30b9<\/h2>\n<p>\u7d9a\u3044\u3066\u300c<strong>\u3042\u308b\u5546\u54c1\u3092\u898b\u305f\u3053\u3068\u304c\u5206\u304b\u308b\u30c7\u30fc\u30bf<\/strong>\u300d\u3092\u7ba1\u7406\u3059\u308b\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u3064\u304f\u308a\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:model ProductAccess -m<\/strong><\/pre>\n<p>\u5f8c\u3067\u51fa\u3066\u304f\u308b\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u969b\u306b\u3001<code>MassAssignmentException<\/code>\u304c\u51fa\u306a\u3044\u3088\u3046<code>$guarded<\/code>\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><code>\/app\/ProductAccess.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass ProductAccess extends Model\r\n{\r\n    <strong>protected $guarded = ['id']; \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p><code>\/database\/migrations\/****_**_**_******_create_product_accesses_table.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass CreateProductAccessesTable extends Migration\r\n{\r\n    <strong>public function up()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        Schema::create('product_accesses', function (Blueprint $table) {<\/strong>\r\n<strong>            $table-&gt;id();<\/strong>\r\n<strong>            $table-&gt;unsignedBigInteger('product_id')-&gt;comment('\u5546\u54c1ID');<\/strong>\r\n<strong>            $table-&gt;string('ip')-&gt;comment('IP\u30a2\u30c9\u30ec\u30b9');<\/strong>\r\n<strong>            $table-&gt;timestamps();<\/strong>\r\n\r\n<strong>            $table-&gt;foreign('product_id')-&gt;references('id')-&gt;on('products');<\/strong>\r\n<strong>            $table-&gt;unique(['product_id', 'ip']);<\/strong>\r\n<strong>        });<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n}<\/pre>\n<p>\u203b\u306a\u304a\u3001\u7279\u5b9a\u306e\u5546\u54c1\u3067IP\u30a2\u30c9\u30ec\u30b9\u304c\u91cd\u8907\u3057\u306a\u3044\u3088\u3046\u306b\u3001<code>product_id<\/code>\u3068<code>ip<\/code>\u3067\u30e6\u30cb\u30fc\u30af\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u304a\u3059\u3059\u3081\u5546\u54c1<\/h2>\n<p>\u6700\u5f8c\u306e\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u96c6\u8a08\u3057\u305f\u304a\u3059\u3059\u3081\u5546\u54c1\u30c7\u30fc\u30bf\u3092\u7ba1\u7406\u3059\u308b\u3082\u306e\u3067\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:model ProductRecommendation -m<\/strong><\/pre>\n<p>\u4f5c\u6210\u3055\u308c\u305f\u30e2\u30c7\u30eb\u306b\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><code>\/app\/ProductRecommendation.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass ProductRecommendation extends Model\r\n{\r\n    \/\/ \u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\r\n    <strong>public function product() {<\/strong>\r\n\r\n<strong>        return $this-&gt;belongsTo('App\\Product', 'product_id', 'id');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u540c\u3058\u304f\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3067\u3059\u3002<\/p>\n<p><code>\/database\/migrations\/****_**_**_******_create_product_recommendations_table.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass CreateProductRecommendationsTable extends Migration\r\n{\r\n    <strong>public function up()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        Schema::create('product_recommendations', function (Blueprint $table) {<\/strong>\r\n<strong>            $table-&gt;id();<\/strong>\r\n<strong>            $table-&gt;unsignedBigInteger('product_id')-&gt;comment('\u304a\u3059\u3059\u3081\u5546\u54c1ID');<\/strong>\r\n<strong>            $table-&gt;unsignedBigInteger('original_product_id')-&gt;comment('\u5143\u306e\u5546\u54c1ID');<\/strong>\r\n<strong>            $table-&gt;integer('access_count')-&gt;comment('\u30a2\u30af\u30bb\u30b9\u4ef6\u6570');<\/strong>\r\n<strong>            $table-&gt;timestamps();<\/strong>\r\n\r\n<strong>            $table-&gt;foreign('product_id')-&gt;references('id')-&gt;on('products');<\/strong>\r\n<strong>            $table-&gt;foreign('original_product_id')-&gt;references('id')-&gt;on('products');<\/strong>\r\n<strong>        });<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n}<\/pre>\n<p>\u8868\u73fe\u304c\u96e3\u3057\u3044\u306e\u3067\u3059\u304c\u3001<code>product_id<\/code>\u304c\u300c\u304a\u3059\u3059\u3081\u5546\u54c1\u306eID\u300d\u3067\u3001<code>original_product_id<\/code>\u304c\u300c\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u30fb\u30fb\u30fb\u300d\u306e\u300c\u3053\u306e\u5546\u54c1\u300d\u306eID\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u3064\u307e\u308a\u3001\u6d3e\u751f\u3055\u305b\u308b\u5143\u306e\u5546\u54c1\uff09<\/p>\n<p>\u305d\u3057\u3066\u3001<code>access_count<\/code>\u306f\u96c6\u8a08\u3057\u305f\u30a2\u30af\u30bb\u30b9\u56de\u6570\u3092\u4fdd\u5b58\u3059\u308b\u306e\u3067\u3001<strong>\u3053\u306e\u6570\u5b57\u304c\u5927\u304d\u3051\u308c\u3070\u5927\u304d\u3044\u307b\u3069\u95a2\u9023\u304c\u6df1\u3044\u3068\u8a00\u3048\u307e\u3059\u3002<\/strong><\/p>\n<p>\u3067\u306f\u3001\u3053\u306e\u6642\u70b9\u3067\u4e00\u5ea6\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u30c6\u30fc\u30d6\u30eb\u306e\u4e2d\u8eab\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7571\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_3.png\" alt=\"\" width=\"552\" height=\"272\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_3.png 552w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_3-300x148.png 300w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7572\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_4.png\" alt=\"\" width=\"354\" height=\"255\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_4.png 354w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_4-300x216.png 300w\" sizes=\"auto, (max-width: 354px) 100vw, 354px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7573\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_5.png\" alt=\"\" width=\"414\" height=\"275\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_5.png 414w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_5-300x199.png 300w\" sizes=\"auto, (max-width: 414px) 100vw, 414px\" \/><\/p>\n<h1>Seeder\u3067\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u3064\u304f\u308b<\/h1>\n<p>\u6b21\u306b\u958b\u767a\u304c\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\uff08Seeder\uff09\u3092\u7528\u610f\u3057\u3066\u304a\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:seed ProductsTableSeeder<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>Seeder<\/code>\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><code>\/database\/seeds\/ProductsTableSeeder.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass ProductsTableSeeder extends Seeder\r\n{\r\n    <strong>public function run()\r\n    {\r\n        for($i = 1 ; $i &lt;= 25 ; $i++) {\r\n\r\n            $product = new \\App\\Product();\r\n            $product-&gt;name = '\u5546\u54c1\u540d '. $i;\r\n            $product-&gt;image_url = 'https:\/\/via.placeholder.com\/150?text=Product '. $i;\r\n            $product-&gt;save();\r\n\r\n        }\r\n\r\n        $products = \\App\\Product::get();\r\n\r\n        for($i = 1 ; $i &lt;= 100 ; $i++) {\r\n\r\n            $product_id = $products-&gt;random()-&gt;id;\r\n            $ip = Arr::random([\r\n                '1.1.1.1',\r\n                '2.2.2.2',\r\n                '3.3.3.3',\r\n                '4.4.4.4',\r\n                '5.5.5.5',\r\n                '6.6.6.6',\r\n                '7.7.7.7',\r\n                '8.8.8.8',\r\n                '9.9.9.9',\r\n                '10.10.10.10',\r\n            ]);\r\n\r\n            $access = \\App\\ProductAccess::firstOrNew([\r\n                'product_id' =&gt; $product_id,\r\n                'ip' =&gt; $ip\r\n            ]);\r\n            $access-&gt;save();\r\n\r\n        }\r\n    }<\/strong>\r\n}<\/pre>\n<p>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3068\u3057\u3066\u7528\u610f\u3059\u308b\u306e\u306f\u3001<code>products<\/code>\u3068<code>product_accesses<\/code>\u30c6\u30fc\u30d6\u30eb\u306e\uff12\u3064\u3067\u3059\u3002<\/p>\n<p>\u203b\u3061\u306a\u307f\u306b\u753b\u50cf\u306eURL\u306b\u306f\u3001<a href=\"https:\/\/placeholder.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Placeholder.com<\/a> \u3092\u4f7f\u308f\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f\u3002\uff08\u3044\u3064\u3082\u91cd\u5b9d\u3057\u3066\u3044\u307e\u3059\ud83d\ude09\u2728\uff09<\/p>\n<p>\u3067\u306f\u3001\u5909\u66f4\u3057\u305f<code>Seeder<\/code>\u3092<code>Laravel<\/code>\u306b\u767b\u9332\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><code>\/database\/seeds\/DatabaseSeeder.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass DatabaseSeeder extends Seeder\r\n{\r\n    public function run()\r\n    {\r\n         \/\/ $this-&gt;call(UsersTableSeeder::class);\r\n         <strong>$this-&gt;call(ProductsTableSeeder::class); \/\/ \ud83d\udc48 \u8ffd\u52a0<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u3067\u306f\u6700\u5f8c\u306b\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u518d\u69cb\u7bc9\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7575\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_6.png\" alt=\"\" width=\"569\" height=\"367\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_6.png 569w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_6-300x193.png 300w\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7576\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_7.png\" alt=\"\" width=\"544\" height=\"399\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_7.png 544w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_7-300x220.png 300w\" sizes=\"auto, (max-width: 544px) 100vw, 544px\" \/><\/p>\n<h1>\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u62bd\u51fa\u3059\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u304b\u3089\u304c\u4eca\u56de\u306e\u30e1\u30a4\u30f3\u300c<strong>\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059\uff08\uff1d\u304a\u3059\u3059\u3081\u5546\u54c1\uff09<\/strong>\u300d\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p>\u4f7f\u3044\u52dd\u624b\u304c\u3044\u3044\u3068\u601d\u3044\u307e\u3059\u306e\u3067\u3001\u4eca\u56de\u306f\u30e2\u30c7\u30eb<code>Product<\/code>\u306e\u4e2d\u306b<code>updateRecommendation()<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass Product extends Model\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    \/\/ Others\r\n    <strong>public function updateRecommendation() {<\/strong>\r\n\r\n<strong>        $id = $this-&gt;id;<\/strong>\r\n<strong>        $ip_addresses = $this-&gt;accesses-&gt;pluck('ip');                   \/\/ \u3053\u306e\u5546\u54c1\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305fIP<\/strong>\r\n\r\n<strong>        \/\/ IP\u304c\u30a2\u30af\u30bb\u30b9\u3057\u305f\u4ed6\u306e\u5546\u54c1\u3092\u53d6\u5f97 \u30fb\u30fb\u30fb \u2460<\/strong>\r\n<strong>        $products = \\App\\ProductAccess::whereIn('ip', $ip_addresses)<\/strong>\r\n<strong>            -&gt;where('product_id', '!=', $id)<\/strong>\r\n<strong>            -&gt;get();<\/strong>\r\n\r\n<strong>        \/\/ \u304a\u3059\u3059\u3081\u5546\u54c1\u306e\u30c7\u30fc\u30bf\u52a0\u5de5 \u30fb\u30fb\u30fb \u2461<\/strong>\r\n<strong>        $access_counts = $products<\/strong>\r\n<strong>            -&gt;groupBy('product_id')    \/\/ \u5546\u54c1\u3067\u30b0\u30eb\u30fc\u30d7\u5316<\/strong>\r\n<strong>            -&gt;map(function($products){ \/\/ \u30c7\u30fc\u30bf\u4ef6\u6570\u3092\u8fd4\u3059<\/strong>\r\n\r\n<strong>                return $products-&gt;count();<\/strong>\r\n\r\n<strong>            })<\/strong>\r\n<strong>            -&gt;filter(function($product_count){ \/\/ \u30c7\u30fc\u30bf\u4ef6\u6570\u304c\uff13\u4ee5\u4e0a\u306e\u3082\u306e\u3060\u3051\u306b\u3059\u308b<\/strong>\r\n\r\n<strong>                return ($product_count &gt;= 3);<\/strong>\r\n\r\n<strong>            })<\/strong>\r\n<strong>            -&gt;sortDesc();<\/strong>\r\n\r\n<strong>        \/\/ \u304a\u3059\u3059\u3081\u30c7\u30fc\u30bf\u3092\u5168\u524a\u9664\u3057\u3066\u65b0\u898f\u767b\u9332 \u30fb\u30fb\u30fb \u2462<\/strong>\r\n<strong>        $this-&gt;recommendations()-&gt;delete();<\/strong>\r\n\r\n<strong>        foreach($access_counts as $product_id =&gt; $access_count) {<\/strong>\r\n\r\n<strong>            $recommendation = new \\App\\ProductRecommendation;<\/strong>\r\n<strong>            $recommendation-&gt;original_product_id = $id;<\/strong>\r\n<strong>            $recommendation-&gt;product_id = $product_id;<\/strong>\r\n<strong>            $recommendation-&gt;access_count = $access_count;<\/strong>\r\n<strong>            $recommendation-&gt;save();<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        \/\/ \u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3057\u305f\u65e5\u6642\u3092\u5909\u66f4 \u30fb\u30fb\u30fb \u2463<\/strong>\r\n<strong>        $this-&gt;recommendation_updated_at = now();<\/strong>\r\n<strong>        $this-&gt;save();<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3053\u306e\u4e2d\u3067\u3084\u3063\u3066\u3044\u308b\u4f5c\u696d\u3092\u9806\u306b\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u2460 IP\u304c\u30a2\u30af\u30bb\u30b9\u3057\u305f\u4ed6\u306e\u5546\u54c1\u3092\u53d6\u5f97<\/strong><\/p>\n<p>\u307e\u305a\u7279\u5b9a\u306e\u5546\u54c1\u30c7\u30fc\u30bf\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u30c7\u30fc\u30bf\u3092<code>ProductAccess<\/code>\u304b\u3089\u53d6\u5f97\u3057\u307e\u3059\u3002\uff08\u304a\u3059\u3059\u3081\u3059\u308b\u306e\u306f\u3001\u4ed6\u306e\u5546\u54c1\u30c7\u30fc\u30bf\u306a\u306e\u3067\u81ea\u5206\u81ea\u8eab\u306e\u9664\u5916\u3059\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\uff09<\/p>\n<p><strong>\u2461 \u304a\u3059\u3059\u3081\u5546\u54c1\u306e\u30c7\u30fc\u30bf\u52a0\u5de5<\/strong><\/p>\n<p>\u3053\u3053\u304c\u4eca\u56de\u3067\u5c11\u3057\u3060\u3051\u4e0a\u7d1a\u30b3\u30fc\u30b9\u3068\u3044\u3046\u304b\u3001\u305c\u3072<strong>\u300c\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u4f7f\u3048\u3070\u3053\u3093\u306a\u30ab\u30f3\u30b8\u3067\u30c7\u30fc\u30bf\u52a0\u5de5\u3067\u304d\u308b\u3088\ud83d\udc4d\u300d<\/strong>\u3068\u3044\u3046\u306e\u3092\u77e5\u3063\u3066\u307b\u3057\u304b\u3063\u305f\u90e8\u5206\u306b\u306a\u308a\u307e\u3059\u3002\u3072\u3068\u3064\u305a\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001<code>groupBy()<\/code>\u3067\u3059\u3002<\/p>\n<pre><strong>-&gt;groupBy('product_id')<\/strong>    \/\/ \u5546\u54c1\u3067\u30b0\u30eb\u30fc\u30d7\u5316<\/pre>\n<p>\u3053\u3053\u3067\u306f<code>DB<\/code>\u304b\u3089\u53d6\u5f97\u3057\u305f\u3070\u304b\u308a\u306e\u30c7\u30fc\u30bf\uff08\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\uff09\u3092\u5546\u54c1ID\u3054\u3068\u306b\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7579\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_4.png\" alt=\"\" width=\"314\" height=\"420\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_4.png 314w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_4-224x300.png 224w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/><\/p>\n<p>\u2193\u2193\u2193\u3000\u5143\u30c7\u30fc\u30bf\u3092<code>product_id<\/code>\u3067\u30b0\u30eb\u30fc\u30d7\u5316<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7580\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_5.png\" alt=\"\" width=\"331\" height=\"510\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_5.png 331w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_5-195x300.png 195w\" sizes=\"auto, (max-width: 331px) 100vw, 331px\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u4eca\u56de\u5fc5\u8981\u306a\u306e\u306f\u30a2\u30af\u30bb\u30b9\u56de\u6570\uff08\u3064\u307e\u308a\u95a2\u9023\u5ea6\uff09\u306a\u306e\u3067<code>map()<\/code>\u3067\u5546\u54c1ID\u3054\u3068\u306e\u30a2\u30af\u30bb\u30b9\u56de\u6570\u306b\u5909\u63db\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>-&gt;map(function($products){ \/\/ \u30c7\u30fc\u30bf\u4ef6\u6570\u3092\u8fd4\u3059<\/strong>\r\n\r\n<strong>    return $products-&gt;count();<\/strong>\r\n\r\n<strong>})<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u4e2d\u8eab\u306f\u3053\u3046\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7581\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_6.png\" alt=\"\" width=\"90\" height=\"218\" \/><\/p>\n<p>\u3055\u3089\u306b\u3001\u30a2\u30af\u30bb\u30b9\u56de\u6570\u304c\uff11\u56de\u3060\u3051\u3067\u306f\u304a\u3059\u3059\u3081\u5546\u54c1\u3068\u306f\u3044\u3048\u306a\u3044\u306e\u3067\u3001\u4eca\u56de\u306f<code>filter()<\/code>\u3067\uff13\u4ef6\u4ee5\u4e0a\u306e\u3082\u306e\u3060\u3051\u3092\u6b8b\u3059\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>-&gt;filter(function($product_count){ \/\/ \u30c7\u30fc\u30bf\u4ef6\u6570\u304c\uff13\u4ee5\u4e0a\u306e\u3082\u306e\u3060\u3051\u306b\u3059\u308b\r\n\r\n    return ($product_count &gt;= 3);\r\n\r\n})<\/strong><\/pre>\n<p>\u7d50\u679c\u306f\u3053\u308c\u3060\u3051\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7582\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_7.png\" alt=\"\" width=\"80\" height=\"178\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u3053\u306e\u30c7\u30fc\u30bf\u306f\u30a2\u30af\u30bb\u30b9\u56de\u6570\uff08\u95a2\u9023\u5ea6\uff09\u304c\u591a\u3044\u9806\u306b\u306f\u4e26\u3093\u3067\u3044\u306a\u3044\u306e\u3067\u3001\u6700\u5f8c\u306b<code>sortDesc()<\/code>\u3092\u4f7f\u3063\u3066\u4e26\u3079\u66ff\u3048\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3059\u308b\u3068\u6700\u7d42\u7684\u306b\u30c7\u30fc\u30bf\u306f\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7583\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/shelf_qr_8.png\" alt=\"\" width=\"82\" height=\"176\" \/><\/p>\n<p>\u3053\u308c\u304c\u304a\u3059\u3059\u3081\u5546\u54c1\u306e\u30c7\u30fc\u30bf\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><strong>\u2462 \u304a\u3059\u3059\u3081\u30c7\u30fc\u30bf\u3092\u5168\u524a\u9664\u3057\u3066\u65b0\u898f\u767b\u9332<\/strong><\/p>\n<p>\u304a\u3059\u3059\u3081\u5546\u54c1\u306e\u30c7\u30fc\u30bf\u3092\u62bd\u51fa\u3057\u305f\u3089\u5168\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u3001\u65b0\u3057\u3044\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\u2463 \u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3057\u305f\u65e5\u6642\u3092\u5909\u66f4<\/strong><\/p>\n<p>\u305d\u3057\u3066\u3001<code>recommendation_updated_at<\/code>\u306b\u73fe\u5728\u306e\u65e5\u6642\u3092\u4fdd\u5b58\u3057\u3001\u300c<strong>\u3044\u3064\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u96c6\u8a08\u3057\u305f\u304b<\/strong>\u300d\u304c\u5206\u304b\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h1>\u4e00\u5b9a\u671f\u9593\u3054\u3068\u306b\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b<\/h1>\n<p>\u6b21\u306b\u3001\u304a\u3059\u3059\u3081\u5546\u54c1\u306e\u96c6\u8a08\u3092<strong>\u3042\u308b\u4e00\u5b9a\u671f\u9593\u3092\u8d85\u3048\u3066\u3044\u305f\u3089\u81ea\u52d5\u66f4\u65b0<\/strong>\u3059\u308b\u305f\u3081\u306b<code>shouldUpdateRecommendation()<\/code>\u3092<code>Product<\/code>\u30e2\u30c7\u30eb\u5185\u306b\u3064\u304f\u3063\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><code>\/app\/Product.php<\/code><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App;\r\n\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass Product extends Model\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>public function shouldUpdateRecommendation() { \/\/ \u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3059\u3079\u304d\u304b\u3069\u3046\u304b\u30c1\u30a7\u30c3\u30af<\/strong>\r\n\r\n<strong>        return (<\/strong>\r\n<strong>            is_null($this-&gt;recommendation_updated_at) ||<\/strong>\r\n<strong>            now()-&gt;diffInDays($this-&gt;recommendation_updated_at) &gt;= 3 \/\/ \u6700\u5f8c\u306b\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3057\u3066\u304b\u3089\uff13\u65e5\u4ee5\u4e0a\u306e\u5834\u5408<\/strong>\r\n<strong>        );<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u5185\u5bb9\u3068\u3057\u3066\u306f\u3001<code>pruducts<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u3064\u304f\u3063\u305f\u30d5\u30a3\u30fc\u30eb\u30c9<code>recommendation_updated_at<\/code>\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001\u4ee5\u4e0b\uff12\u3064\u306e\u5834\u5408\u306f<code>true<\/code>\u3092\u8fd4\u3059\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u307e\u3060\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u96c6\u8a08\u3057\u3066\u306a\u3044<\/li>\n<li>\u524d\u56de\u306e\u96c6\u8a08\u304b\u3089\uff08\u4eca\u56de\u306e\u5834\u5408\u306f\uff09\uff13\u65e5\u4ee5\u4e0a\u7d4c\u904e\u3057\u3066\u3044\u308b<\/li>\n<\/ul>\n<h1>\u4f7f\u3044\u65b9<\/h1>\n<p>\u3067\u306f\u3001\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u81ea\u52d5\u7684\u306b\u96c6\u8a08\u3059\u308b\u65b9\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u30c6\u30b9\u30c8\u3068\u3057\u3066\u3001\u4f8b\u3048\u3070\u300c<strong>http:\/\/*****\/product\/1<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u30eb\u30fc\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b\u306a\u304a\u3001\u5b9f\u969b\u306f\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u3092\u3064\u304f\u3063\u3066\u30b3\u30fc\u30c9\u3092\u5206\u3051\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n<p><code>\/routes\/web.php<\/code><\/p>\n<pre><strong>Route::get('product\/{product}', function(\\App\\Product $product){\r\n\r\n    if($product-&gt;shouldUpdateRecommendation()) {\r\n\r\n        $product-&gt;updateRecommendation();\r\n\r\n    }\r\n\r\n    $product-&gt;load('recommendations.product'); \/\/ \u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u8aad\u307f\u8fbc\u307f\r\n\r\n    \/\/ \u3053\u3053\u3067\u4f55\u304b\r\n\r\n});<\/strong><\/pre>\n<p>\u4e2d\u8eab\u3068\u3057\u3066\u306f\u3001<code>shouldUpdateRecommendation()<\/code>\u3067\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u66f4\u65b0\u3059\u3079\u304d\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u3082\u3057\u66f4\u65b0\u3059\u3079\u304d\u306a\u3089<code>updateRecommendation()<\/code>\u3092\u5b9f\u884c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u3042\u308b\u4e00\u5b9a\u671f\u9593\u3054\u3068\u81ea\u52d5\u7684\u306b\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u6700\u65b0\u30c7\u30fc\u30bf\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h1>\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u4e00\u89a7\u8868\u793a\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u305b\u3063\u304b\u304f\u304a\u3059\u3059\u3081\u5546\u54c1\u3092\u96c6\u8a08\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u3001\u5148\u307b\u3069\u306e\u30eb\u30fc\u30c8\u306b\u30d3\u30e5\u30fc\u3092\u8ffd\u52a0\u3057\u3066\u30ea\u30b9\u30c8\u8868\u793a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><code>\/routes\/web.php<\/code><\/p>\n<pre><strong>Route::get('product\/{product}', function(\\App\\Product $product){\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    return view('product')-&gt;with([\r\n        'product' =&gt; $product\r\n    ]);\r\n\r\n});<\/strong><\/pre>\n<h2>\u30d3\u30e5\u30fc\u3092\u3064\u304f\u308b<\/h2>\n<p>\u7d9a\u3044\u3066\u30d3\u30e5\u30fc\u3067\u3059\u3002<br \/>\n<code>Vue.js<\/code>\u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u30b7\u30f3\u30d7\u30eb\u306b\u6a2a\u30b9\u30af\u30ed\u30fc\u30eb\u8868\u793a\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p><code>\/resources\/views\/product.blade.php<\/code><\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n    &lt;style&gt;\r\n\r\n        #page-title {\r\n\r\n            margin-bottom: 0;\r\n            margin-left: 10px;\r\n            color: #776;\r\n\r\n        }\r\n\r\n        .scroll-box {\r\n\r\n            overflow-x: auto;\r\n            overflow-y: hidden;\r\n            white-space: nowrap;\r\n\r\n        }\r\n\r\n        .scroll-box img {\r\n\r\n            max-height: 200px;\r\n\r\n        }\r\n\r\n        .scroll-item {\r\n\r\n            display: inline-block;\r\n            margin: 10px;\r\n\r\n        }\r\n\r\n    &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;div id=\"app\"&gt;\r\n        &lt;h3 id=\"page-title\"&gt;\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059 &amp;#x1F389;&lt;\/h3&gt;\r\n        <strong>&lt;div class=\"scroll-box\"&gt;<\/strong>\r\n<strong>            &lt;a :href=\"'\/product\/'+ recommendation.product.id\" class=\"scroll-item\" v-for=\"recommendation in product.recommendations\"&gt;<\/strong>\r\n<strong>               &lt;img :src=\"recommendation.product.image_url\"&gt;<\/strong>\r\n<strong>               &lt;div v-text=\"recommendation.product.name\"&gt;&lt;\/div&gt;<\/strong>\r\n<strong>            &lt;\/a&gt;<\/strong>\r\n<strong>        &lt;\/div&gt;<\/strong>\r\n    &lt;\/div&gt;\r\n    &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.11\"&gt;&lt;\/script&gt;\r\n    &lt;script&gt;\r\n\r\n        <strong>new Vue({<\/strong>\r\n<strong>            el: '#app',<\/strong>\r\n<strong>            data: {<\/strong>\r\n<strong>                product: {!! $product !!}<\/strong>\r\n<strong>            }<\/strong>\r\n<strong>        });<\/strong>\r\n\r\n    &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u5b9f\u969b\u306b\u300chttp:\/\/*****\/product\/1\u300d\u3078\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3057\u3087\u3046\u2757<\/p>\n<p><span style=\"font-size: 1rem;\">\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7567\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_1.png\" alt=\"\" width=\"640\" height=\"240\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_1.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_1-300x113.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u3082\u3061\u308d\u3093\u3001\u30b9\u30e9\u30a4\u30c9\u3055\u305b\u308b\u3068\u5225\u306e\u5546\u54c1\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7568\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_2.png\" alt=\"\" width=\"640\" height=\"239\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_2.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/07\/laravel_recommendation_2-300x112.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\ud83d\udc4d\u2728<\/p>\n<h1>\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<p>\u203b\u305f\u3060\u3057\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3084\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u7528\u610f\u306f\u3054\u81ea\u8eab\u3067\u5b9f\u884c\u3057\u3066\u3044\u305f\u3060\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"\" href=\"https:\/\/blog.capilano-fw.com?download=7585&amp;tmstv=1777534071\" rel=\"nofollow\" id=\"download-link-7585\" data-redirect=\"false\" >\n\tLaravel\u3067\u300c\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a>\n\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u30aa\u30f3\u30e9\u30a4\u30f3\u30b7\u30e7\u30c3\u30d7\u3067\u3088\u304f\u898b\u304b\u3051\u308b\u300c<strong>\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059<\/strong>\u300d\u6a5f\u80fd\u3092<code>Laravel<\/code>\u3067\u3064\u304f\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u30b5\u30a4\u30c8\u3067\u3057\u305f\u3089\u3001\u5546\u54c1\u306e\u30ab\u30c6\u30b4\u30ea\u3092\u542b\u3081\u3066\u96c6\u8a08\u3057\u3066\u3082\u3044\u3044\u3067\u3057\u3087\u3046\u3057\u3001\u304a\u306a\u3058\u3084\u308a\u65b9\u3067\u300c<strong>\u3053\u306e\u5546\u54c1\u3092\u8cb7\u3063\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u8cb7\u3063\u3066\u3044\u307e\u3059<\/strong>\u300d\u6a5f\u80fd\u3082\u3064\u304f\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/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 style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3405 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png\" alt=\"\" width=\"310\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18.png 310w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_18-291x300.png 291w\" sizes=\"auto, (max-width: 310px) 100vw, 310px\" \/>\u300c\u5e74\u9f62\u306e\u305b\u3044\u304b\u3001\u590f\u3067\u3082<br \/>\n\u30db\u30c3\u30c8\u30b3\u30fc\u30d2\u30fc\u3092\u98f2\u3080\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u666e\u6bb5\u304b\u3089\u79c1\u306f\u30a4\u30f3\u30bf\u30fc\u30cd\u30c3\u30c8\u4e0a\u3067\u304a\u8cb7\u3044\u7269\u3092\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3059\u304c\u3001Amazon\u306a\u3069\u3067\u898b\u304b\u3051\u308b\u3042\u308b\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u3044\u3064\u3082\u6c17\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002 \u305d\u306e\u6a5f\u80fd\u306f\u30fb\u30fb &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=7560\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel\u3067\u300c\u3053\u306e\u5546\u54c1\u3092\u898b\u305f\u4eba\u306f\u3053\u3061\u3089\u306e\u5546\u54c1\u3082\u898b\u3066\u3044\u307e\u3059\u300d\u6a5f\u80fd\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":7594,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,12],"tags":[65],"class_list":["post-7560","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-vue-js","tag-65"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7560","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=7560"}],"version-history":[{"count":12,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7560\/revisions"}],"predecessor-version":[{"id":10023,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7560\/revisions\/10023"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/7594"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}