{"id":9122,"date":"2021-05-24T07:00:08","date_gmt":"2021-05-23T22:00:08","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=9122"},"modified":"2021-05-08T00:10:09","modified_gmt":"2021-05-07T15:10:09","slug":"laravel%e3%81%a7%e8%b3%bc%e5%85%a5%e5%b1%a5%e6%ad%b4%e3%81%8b%e3%82%89%e3%83%91%e3%82%bf%e3%83%bc%e3%83%b3%e5%88%86%e6%9e%90%e3%81%97%e3%80%81dm%e3%82%92%e9%80%81%e3%82%8b%e3%82%b7%e3%82%b9%e3%83%86","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=9122","title":{"rendered":"Laravel\u3067\u8cfc\u5165\u5c65\u6b74\u304b\u3089\u30d1\u30bf\u30fc\u30f3\u5206\u6790\u3057\u3001DM\u3092\u9001\u308b\u30b7\u30b9\u30c6\u30e0\u3092\u3064\u304f\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3060\u3051\u306b\u9650\u3089\u305a\u3067\u3059\u304c\u3001\u6700\u8fd1\u306f\u6642\u4ee3\u306e\u5909\u5316\u304c\u3068\u3066\u3082\u65e9\u3044\u306e\u3067\u3001\u5e38\u306b\u81ea\u5206\u3092\u6642\u4ee3\u306b\u5408\u308f\u305b\u3066\u3044\u304b\u306a\u304d\u3083\uff01\u3068\u611f\u3058\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u305d\u308c\u306b\u95a2\u9023\u3057\u3066\u5c11\u3057\u305a\u3064\u8208\u5473\u3092\u3082\u3061\u306f\u3058\u3081\u3066\u3044\u308b\u306e\u304c\u3001<\/p>\n<p><strong style=\"font-size: 35px;\">\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u3082\u3067\u304d\u308b\u30a8\u30f3\u30b8\u30cb\u30a2<\/strong><\/p>\n<p>\u3067\u3059\u3002<\/p>\n<p>\u6b63\u76f4\u306a\u3068\u3053\u308d\u3001\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u306f\u305d\u308c\u307b\u3069\u8eab\u8fd1\u3067\u306f\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3069\u306e\u696d\u754c\u306b\u3082\u95a2\u308f\u3063\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u306e\u3067\u3001\u7814\u7a76\u3082\u517c\u306d\u3066\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u3044\u304f\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u3001<code>Laravel<\/code>\u3092\u4f7f\u3063\u3066\u300c<strong>\u8cfc\u5165\u5c65\u6b74\u304b\u3089\u30d1\u30bf\u30fc\u30f3\u5206\u6790\u3057\u3001DM\u3092\u9001\u308b<\/strong>\u300d\u30b7\u30b9\u30c6\u30e0\u3092\u4f5c\u3063\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b \u5143\u30cd\u30bf\u306f\u300e<a href=\"https:\/\/www.amazon.co.jp\/dp\/4492042474\" target=\"_blank\" rel=\"noopener\">\u30d3\u30b8\u30cd\u30b9\u306e\uff29\uff31\u304c\u9ad8\u307e\u308b\u6cc9\u7530\u5f0f10\u901f\u767a\u60f3\u6cd5<\/a>\u300f\u3068\u3044\u3046\u672c\u306e\u300c<strong>\u4eba\u306f\u597d\u304d\u306a\u3053\u3068\u3092\u7e70\u308a\u8fd4\u3059<\/strong>\u300d\u3068\u3044\u3046\u30eb\u30fc\u30eb\u3067\u3059\u3002\u30dd\u30c3\u30c9\u30ad\u30e3\u30b9\u30c8\u3082\u3088\u304f\u805e\u3044\u3066\u307e\u3057\u305f\uff01<\/p>\n<p>\u305c\u3072\u4f55\u304b\u306e\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2173 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png\" alt=\"\" width=\"300\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24.png 300w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2018\/11\/no_24-281x300.png 281w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>\u300c\u305d\u306e\u6614\u3001\u7d4c\u55b6\u8005\u76ee\u6307\u3057\u3066<br \/>\n\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u672c\u3092<br \/>\n\u8aad\u3093\u3067\u307e\u3057\u305f\u300d<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 8.x<\/p>\n<h1>\u524d\u63d0\u3068\u3057\u3066<\/h1>\n<p>\u3059\u3067\u306b\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3001\u3055\u3089\u306b\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u304c<code>users<\/code>\u30c6\u30fc\u30d6\u30eb\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u524d\u63d0\u3067\u3059\u3002<\/p>\n<p>\u3082\u3057\u307e\u3060\u306e\u65b9\u306f\u3001\u4ee5\u4e0b\u3092\u53c2\u8003\u306b\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>\ud83d\udcdd \u53c2\u8003\u30da\u30fc\u30b8<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/blog.capilano-fw.com\/?p=8301\">Laravel Breeze\u3067\u300c\u30b7\u30f3\u30d7\u30eb\u306a\u300d\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li>\n<li><a href=\"https:\/\/blog.capilano-fw.com\/?p=7827\">Laravel8.x\u4ee5\u964d\u3067\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5<\/a><\/li>\n<\/ul>\n<p><b>\uff08<strong>users \u30c6\u30fc\u30d6\u30eb\u30fb\u30b5\u30f3\u30d7\u30eb<\/strong>\uff09<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9125\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_1.png\" alt=\"\" width=\"538\" height=\"463\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_1.png 538w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_1-300x258.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/p>\n<h1>\u30d1\u30bf\u30fc\u30f3\u5206\u6790\u306e\u65b9\u6cd5<\/h1>\n<p>\u4eca\u56de\u3001\u8cfc\u5165\u5c65\u6b74\u304b\u3089\u898b\u3064\u3051\u51fa\u3059\u30d1\u30bf\u30fc\u30f3\u306f\u4ee5\u4e0b\uff12\u3064\u3067\u3059\u3002<\/p>\n<h2>\u3069\u306e\u304f\u3089\u3044\u306e\u9593\u9694\u3067\u30e2\u30ce\u3092\u8cb7\u3063\u3066\u308b\u304b<\/h2>\n<p>\u904e\u53bb\u306e\u8cfc\u5165\u5c65\u6b74\u304b\u3089\u300c<strong>\u5e73\u5747\u3067\u3069\u306e\u304f\u3089\u3044\u306e\u30b5\u30a4\u30af\u30eb\uff08\u65e5\u6570\uff09<\/strong>\u300d\u3067\u30e2\u30ce\u3092\u8cb7\u3063\u3066\u3044\u308b\u304b\u8a08\u7b97\u3057\u3001\u6700\u5f8c\u306b\u8cfc\u5165\u3057\u305f\u65e5\u304b\u3089\u305d\u306e\u65e5\u6570\u304c\u7d4c\u904e\u3057\u3066\u3044\u305f\u3089\u300c<strong>\u305d\u308d\u305d\u308d\u304a\u8cb7\u3044\u7269\u3057\u307e\u305b\u3093\u304b\ud83d\ude0a<\/strong>\u300d\u3068\u3044\u3046DM\u3092\u9001\u4fe1\u3059\u308b\u3002<\/p>\n<h2>\u3069\u306e\u30ab\u30c6\u30b4\u30ea\u306e\u5546\u54c1\u3092\u8cb7\u3063\u3066\u3044\u308b\u304b<\/h2>\n<p>\u904e\u53bb\u306b\u8cb7\u3063\u305f\u3053\u3068\u306e\u306a\u3044\u30ab\u30c6\u30b4\u30ea\u306e\u5546\u54c1\u3092\u7d39\u4ecb\u3057\u3066\u3082\u304a\u5ba2\u3055\u3093\u306f\u8208\u5473\u306f\u8584\u3044\u306f\u305a\u3067\u3059\u306e\u3067\u3001\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u306e\u4e2d\u304b\u3089\u30d4\u30c3\u30af\u30a2\u30c3\u30d7\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002\uff08\u5b9f\u969b\u306eDM\u306b\u306f\u65b0\u7740\u9806\u306b\u6700\u5927\uff13\u3064\u306e\u5546\u54c1\u3092\u542b\u3081\u308b\uff09<\/p>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u4f5c\u696d\u3057\u3066\u3044\u304d\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\u5546\u54c1\u3068\u8cfc\u5165\u5c65\u6b74\u30c7\u30fc\u30bf\u304c\u306a\u3044\u3068\u30d1\u30bf\u30fc\u30f3\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002<br \/>\n\u305d\u306e\u305f\u3081\u3001\u307e\u305a\u4ee5\u4e0b\uff14\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5546\u54c1\u30ab\u30c6\u30b4\u30ea\uff1a product_categories<\/li>\n<li>\u5546\u54c1\u30c6\u30fc\u30d6\u30eb\uff1a products<\/li>\n<li>\u8cfc\u5165\u5c65\u6b74\u30c6\u30fc\u30d6\u30eb\uff1a orders<\/li>\n<li>\u8cfc\u5165\u5c65\u6b74\u306e\u96c6\u8a08\uff1a order_summaries<\/li>\n<\/ul>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08\u9806\u756a\u5927\u4e8b\u3067\u3059\uff01\uff09<\/p>\n<pre><strong>php artisan make:model ProductCategory -m<\/strong><\/pre>\n<pre><strong>php artisan make:model Product -m<\/strong><\/pre>\n<pre><strong>php artisan make:model Order -m<\/strong><\/pre>\n<pre><strong>php artisan make:model OrderSummary -m<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30e2\u30c7\u30eb\uff06\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u304c\uff14\u30da\u30a2\u4f5c\u6210\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u307e\u305a\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>\u26a0 \u3054\u6ce8\u610f<\/strong><br \/>\n\u4eca\u56de\u306f\u5fc5\u8981\u6700\u4f4e\u9650\u5fc5\u8981\u306a\u30d5\u30a3\u30fc\u30eb\u30c9\u3060\u3051\u4f5c\u3063\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u300c\u4fa1\u683c\u300d\u306a\u3069\u306f\u7528\u610f\u3057\u3066\u3044\u307e\u305b\u3093\u3002<\/p>\n<p><strong>database\/migrations\/****_**_**_******_create_product_categories_table.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\n<strong>public function up()<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    Schema::create('product_categories', function (Blueprint $table) {<\/strong>\r\n<strong>        $table-&gt;id();<\/strong>\r\n<strong>        $table-&gt;string('name')-&gt;comment('\u30ab\u30c6\u30b4\u30ea\u540d');<\/strong>\r\n<strong>        $table-&gt;timestamps();<\/strong>\r\n<strong>    });<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p><strong>database\/migrations\/****_**_**_******_create_orders_table.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\n<strong>public function up()<\/strong>\r\n<strong>{<\/strong>\r\n<strong>    Schema::create('orders', function (Blueprint $table) {<\/strong>\r\n<strong>        $table-&gt;id();<\/strong>\r\n<strong>        $table-&gt;unsignedBigInteger('user_id')-&gt;comment('\u30e6\u30fc\u30b6\u30fcID');<\/strong>\r\n<strong>        $table-&gt;unsignedBigInteger('product_id')-&gt;comment('\u5546\u54c1ID');<\/strong>\r\n<strong>        $table-&gt;timestamps();<\/strong>\r\n\r\n<strong>        $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');<\/strong>\r\n<strong>        $table-&gt;foreign('product_id')-&gt;references('id')-&gt;on('products');<\/strong>\r\n<strong>    });<\/strong>\r\n<strong>}<\/strong><\/pre>\n<p><strong>database\/migrations\/****_**_**_******_create_products_table.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\n<strong>Schema::create('products', function (Blueprint $table) {<\/strong>\r\n<strong>    $table-&gt;id();<\/strong>\r\n<strong>    $table-&gt;unsignedBigInteger('category_id')-&gt;comment('\u30ab\u30c6\u30b4\u30eaID');<\/strong>\r\n<strong>    $table-&gt;string('name')-&gt;comment('\u5546\u54c1\u540d');<\/strong>\r\n<strong>    $table-&gt;timestamps();<\/strong>\r\n\r\n<strong>    $table-&gt;foreign('category_id')-&gt;references('id')-&gt;on('product_categories');<\/strong>\r\n<strong>});<\/strong><\/pre>\n<p><strong>database\/migrations\/****_**_**_******_create_order_summaries_table.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\npublic function up()\r\n{\r\n    <strong>Schema::create('order_summaries', function (Blueprint $table) {<\/strong>\r\n<strong>        $table-&gt;id();<\/strong>\r\n<strong>        $table-&gt;unsignedBigInteger('user_id')-&gt;comment('\u30e6\u30fc\u30b6\u30fcID');<\/strong>\r\n<strong>        $table-&gt;unsignedInteger('interval_days')-&gt;comment('\u8cfc\u5165\u9593\u9694');<\/strong>\r\n<strong>        $table-&gt;date('dm_sending_date')-&gt;comment('DM\u9001\u4fe1\u4e88\u5b9a\u65e5');<\/strong>\r\n<strong>        $table-&gt;timestamps();<\/strong>\r\n\r\n<strong>        $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');<\/strong>\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u307e\u305f\u3001\u5f8c\u3067\u30ea\u30ec\u30fc\u30b7\u30e7\u30f3\u30b7\u30c3\u30d7\u3092\u4f7f\u3046\u306e\u3067\u4ee5\u4e0b\u306e\u5909\u66f4\u3082\u8ffd\u52a0\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>app\/Models\/OrderSummary.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\nclass OrderSummary extends Model\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>\/\/ Relationship<\/strong>\r\n<strong>    public function user() {<\/strong>\r\n\r\n<strong>        return $this-&gt;belongsTo(User::class, 'user_id', 'id');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p><strong>app\/Models\/Order.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\nclass Order extends Model\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n<strong>    \/\/ Relationship<\/strong>\r\n<strong>    public function product() {<\/strong>\r\n\r\n<strong>        return $this-&gt;belongsTo(Product::class, 'product_id', 'id');<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<h1>\u30a4\u30d9\u30f3\u30c8\u3092\u3064\u304f\u308b<\/h1>\n<p><code>order_summaries<\/code>\u30c6\u30fc\u30d6\u30eb\u306f\u300c<strong>\u8cfc\u5165\u5c65\u6b74\u306e\u96c6\u8a08\u30c7\u30fc\u30bf<\/strong>\u300d\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306b\u3064\u304f\u3063\u3066\u3044\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001\u8cfc\u5165\u3055\u308c\u308b\u305f\u3073\u306b\u81ea\u52d5\u7684\u306b\u30c7\u30fc\u30bf\u66f4\u65b0\u3067\u304d\u308b\u3088\u3046\u306b\u30a4\u30d9\u30f3\u30c8\u3092\u3064\u304f\u3063\u3066\u304a\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 OrderSaved<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>app\/Events\/OrderSaved.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Events;\r\n\r\n<strong>use App\\Models\\Order;<\/strong>\r\n<strong>use App\\Models\\OrderSummary;<\/strong>\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass OrderSaved\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>public function __construct(Order $order)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $user_id = $order-&gt;user_id;<\/strong>\r\n<strong>        $interval_days = [];<\/strong>\r\n<strong>        $orders = Order::where('user_id', $user_id)<\/strong>\r\n<strong>            -&gt;orderBy('created_at', 'asc')<\/strong>\r\n<strong>            -&gt;get();<\/strong>\r\n\r\n<strong>        foreach ($orders as $index =&gt; $order) {<\/strong>\r\n\r\n<strong>            if($index &gt; 0) { \/\/ \u30c7\u30fc\u30bf\uff12\u4ef6\u76ee\u304b\u3089<\/strong>\r\n\r\n<strong>                $order_at = $order-&gt;created_at;<\/strong>\r\n<strong>                $interval_days[] = $order_at-&gt;diffInDays($prev_order_at);<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>            $prev_order_at = $order-&gt;created_at;<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        $summary = OrderSummary::firstOrNew(['user_id' =&gt; $user_id]);<\/strong>\r\n<strong>        $summary-&gt;user_id = $user_id;<\/strong>\r\n<strong>        $interval_days_count = count($interval_days);<\/strong>\r\n\r\n<strong>        if($interval_days_count &gt; 0) {<\/strong>\r\n\r\n<strong>            $interval_days_total = array_sum($interval_days);<\/strong>\r\n<strong>            $new_interval_days = round($interval_days_total \/ $interval_days_count);<\/strong>\r\n<strong>            $summary-&gt;interval_days = $new_interval_days;<\/strong>\r\n<strong>            $summary-&gt;dm_sending_date = $orders-&gt;max('created_at')-&gt;addDays($new_interval_days);<\/strong>\r\n<strong>            $summary-&gt;save();<\/strong>\r\n\r\n<strong>        } else if($summary-&gt;exists()) { \/\/ \u3082\u3057\u306a\u3051\u308c\u3070\u524a\u9664<\/strong>\r\n\r\n<strong>            $summary-&gt;delete();<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n\/\/ \u4ee5\u4e0b\u7701\u7565<\/pre>\n<p>\u305d\u3057\u3066\u3001<code>OrderSaved<\/code>\u30a4\u30d9\u30f3\u30c8\u3092\u30e2\u30c7\u30eb\u306b\u30bb\u30c3\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Models\/Order.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Models;\r\n\r\n<strong>use App\\Events\\OrderSaved;<\/strong>\r\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\r\nuse Illuminate\\Database\\Eloquent\\Model;\r\n\r\nclass Order extends Model\r\n{\r\n    use HasFactory;\r\n\r\n    <strong>protected $dispatchesEvents = [<\/strong>\r\n<strong>        'saved' =&gt; OrderSaved::class \/\/ \ud83d\udc48 \u3053\u3053<\/strong>\r\n<strong>    ];<\/strong>\r\n}<\/pre>\n<p>\u3053\u308c\u3067<code>Order<\/code>\u30e2\u30c7\u30eb\u3067\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\uff06\u5909\u66f4\u3057\u305f\u3089\u81ea\u52d5\u7684\u306b\u96c6\u8a08\u30c7\u30fc\u30bf\u3092\u4f5c\u3063\u3066\u304f\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h1>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\uff13\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u305d\u308c\u305e\u308c\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<ul>\n<li>product_categories: \u5546\u54c1\u30ab\u30c6\u30b4\u30ea<\/li>\n<li>products: \u5546\u54c1<\/li>\n<li>orders: \u8cfc\u5165\u5c65\u6b74<\/li>\n<\/ul>\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:seed ProductCategoriesTableSeeder<\/strong><\/pre>\n<pre><strong>php artisan make:seed ProductsTableSeeder<\/strong><\/pre>\n<pre><strong>php artisan make:seed OrdersTableSeeder<\/strong><\/pre>\n<p>\u3059\u308b\u3068<code>Seeder<\/code>\u7528\u306e\u30d5\u30a1\u30a4\u30eb\u304c\uff13\u3064\u4f5c\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u4e2d\u8eab\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><strong>database\/seeders\/ProductCategoriesTableSeeder.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace Database\\Seeders;\r\n\r\n<strong>use App\\Models\\ProductCategory;<\/strong>\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass ProductCategoriesTableSeeder extends Seeder\r\n{\r\n    public function run()\r\n    {\r\n        <strong>$names = [<\/strong>\r\n<strong>            '\u672c\u30fb\u30b3\u30df\u30c3\u30af\u30fb\u96d1\u8a8c',<\/strong>\r\n<strong>            'DVD\u30fb\u30df\u30e5\u30fc\u30b8\u30c3\u30af\u30fb\u30b2\u30fc\u30e0',<\/strong>\r\n<strong>            '\u5bb6\u96fb\u30fb\u30ab\u30e1\u30e9\u30fbAV\u6a5f\u5668',<\/strong>\r\n<strong>            '\u30d1\u30bd\u30b3\u30f3\u30fb\u30aa\u30d5\u30a3\u30b9\u7528\u54c1',<\/strong>\r\n<strong>            '\u30db\u30fc\u30e0\uff06\u30ad\u30c3\u30c1\u30f3\u30fb\u30da\u30c3\u30c8\u30fbDIY'<\/strong>\r\n<strong>        ];<\/strong>\r\n\r\n<strong>        foreach ($names as $name) {<\/strong>\r\n\r\n<strong>            $category = new ProductCategory();<\/strong>\r\n<strong>            $category-&gt;name = $name;<\/strong>\r\n<strong>            $category-&gt;save();<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n    }\r\n}<\/pre>\n<p><strong>database\/seeders\/ProductsTableSeeder.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace Database\\Seeders;\r\n\r\n<strong>use App\\Models\\Product;<\/strong>\r\nuse App\\Models\\ProductCategory;\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass ProductsTableSeeder extends Seeder\r\n{\r\n    <strong>public function run()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $category_ids = ProductCategory::pluck('id');<\/strong>\r\n\r\n<strong>        for($i = 0 ; $i &lt; 100 ; $i++) {<\/strong>\r\n\r\n<strong>            $product = new Product();<\/strong>\r\n<strong>            $product-&gt;category_id = $category_ids-&gt;random();<\/strong>\r\n<strong>            $product-&gt;name = '\u30c6\u30b9\u30c8\u5546\u54c1\u540d - '. $i;<\/strong>\r\n<strong>            $product-&gt;save();<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p><strong>database\/seeders\/OrdersTableSeeder.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace Database\\Seeders;\r\n\r\n<strong>use App\\Models\\Order;<\/strong>\r\n<strong>use App\\Models\\Product;<\/strong>\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass OrdersTableSeeder extends Seeder\r\n{\r\n    <strong>public function run()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $order_details = [ \/\/ \u30ad\u30fc\u306f\u30e6\u30fc\u30b6\u30fcID<\/strong>\r\n<strong>            1 =&gt; [<\/strong>\r\n<strong>                'order_interval' =&gt; 1, \/\/ \u8cfc\u5165\u9593\u9694\uff08\u6708\uff09,<\/strong>\r\n<strong>                'product_category_ids' =&gt; [1, 2] \/\/ \u8cfc\u5165\u30ab\u30c6\u30b4\u30ea<\/strong>\r\n<strong>            ],<\/strong>\r\n<strong>            2 =&gt; [<\/strong>\r\n<strong>                'order_interval' =&gt; 3, \/\/ \u8cfc\u5165\u9593\u9694\uff08\u6708\uff09,<\/strong>\r\n<strong>                'product_category_ids' =&gt; [2, 3] \/\/ \u8cfc\u5165\u30ab\u30c6\u30b4\u30ea<\/strong>\r\n<strong>            ],<\/strong>\r\n<strong>            3 =&gt; [<\/strong>\r\n<strong>                'order_interval' =&gt; 5, \/\/ \u8cfc\u5165\u9593\u9694\uff08\u6708\uff09,<\/strong>\r\n<strong>                'product_category_ids' =&gt; [3, 4, 5] \/\/ \u8cfc\u5165\u30ab\u30c6\u30b4\u30ea<\/strong>\r\n<strong>            ]<\/strong>\r\n<strong>        ];<\/strong>\r\n\r\n<strong>        foreach ($order_details as $user_id =&gt; $order_detail) {<\/strong>\r\n\r\n<strong>            $order_count = rand(5, 25); \/\/ \u30e6\u30fc\u30b6\u30fc\u3054\u3068\u306e\u6ce8\u6587\u56de\u6570<\/strong>\r\n\r\n<strong>            for($i = 0 ; $i &lt; $order_count ; $i++) {<\/strong>\r\n\r\n<strong>                $order_interval = $order_detail['order_interval'];<\/strong>\r\n<strong>                $product_category_ids = $order_detail['product_category_ids'];<\/strong>\r\n<strong>                $dt = today()<\/strong>\r\n<strong>                    -&gt;subMonth($order_interval * $i)<\/strong>\r\n<strong>                    -&gt;addDays(rand(-15, 15)); \/\/ \u3053\u3053\u306f\u8aa4\u5dee\u3092\u30e9\u30f3\u30c0\u30e0\u3067\u4f5c\u6210<\/strong>\r\n<strong>                $product_ids = Product::whereIn('category_id', $product_category_ids)-&gt;pluck('id');<\/strong>\r\n\r\n<strong>                $order = new Order();<\/strong>\r\n<strong>                $order-&gt;user_id = $user_id;<\/strong>\r\n<strong>                $order-&gt;product_id = $product_ids-&gt;random();<\/strong>\r\n<strong>                $order-&gt;created_at = $dt;<\/strong>\r\n<strong>                $order-&gt;save();<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\uff13\u3064\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u5909\u66f4\u3067\u304d\u305f\u3089\u3001\u3053\u308c\u3089\u3092<code>Laravel<\/code>\u306b\u767b\u9332\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p><strong>database\/seeders\/DatabaseSeeder.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\npublic function run()\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>$this-&gt;call(ProductCategoriesTableSeeder::class);<\/strong>\r\n<strong>    $this-&gt;call(ProductsTableSeeder::class);<\/strong>\r\n<strong>    $this-&gt;call(OrdersTableSeeder::class);<\/strong>\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u5468\u308a\u306e\u8a2d\u5b9a\u306f\u5b8c\u4e86\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067DB\u3092\u518d\u69cb\u7bc9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u3046\u307e\u304f\u3044\u3051\u3070\u3001\uff14\u3064\u306e\u30c6\u30fc\u30d6\u30eb\u304c\u4f5c\u6210\u3055\u308c\u3066\u305d\u306e\u5168\u3066\u306b\u30c7\u30fc\u30bf\u304c\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001<code>order_summaries<\/code>\u30c6\u30fc\u30d6\u30eb\u3060\u3051\u306f\u30a4\u30ec\u30ae\u30e5\u30e9\u30fc\u306a\u306e\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9126\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_2.png\" alt=\"\" width=\"453\" height=\"319\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_2.png 453w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_2-300x211.png 300w\" sizes=\"auto, (max-width: 453px) 100vw, 453px\" \/><\/p>\n<p>\u3046\u307e\u304f\u300c<strong>\u8cfc\u5165\u9593\u9694<\/strong>\u300d\u3068\u300c<strong>DM\u9001\u4fe1\u4e88\u5b9a\u65e5<\/strong>\u300d\u304c\u4fdd\u5b58\u3055\u308c\u3066\u308b\u3088\u3046\u3067\u3059\ud83d\udc4d<\/p>\n<p>\u203b \u306a\u304a\u3001<code>OrdersTableSeeder<\/code>\u5185\u3067\u6ce8\u6587\u56de\u6570\u3084\u8cfc\u5165\u65e5\u6642\u306b\u30e9\u30f3\u30c0\u30e0\u306a\u8aa4\u5dee\u3092\u4e0e\u3048\u3066\u3044\u308b\u306e\u3067\u540c\u3058\u30c7\u30fc\u30bf\u306b\u306f\u306a\u3063\u3066\u3044\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>DM\u3092\u9001\u4fe1\u3059\u308b\u90e8\u5206\u3092\u3064\u304f\u308b<\/h1>\n<h2>\u30e1\u30fc\u30eb\u90e8\u5206\u3092\u3064\u304f\u308b<\/h2>\n<p>\u4eca\u56de\u306f\u30b7\u30f3\u30d7\u30eb\u306b\u30e1\u30fc\u30eb\u3067<code>DM<\/code>\u3092\u9001\u4fe1\u3059\u308b\u3053\u3068\u306b\u3057\u307e\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:mail OrderCycleHasCome<\/strong><\/pre>\n<p>\u3059\u308b\u3068\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>app\/Mail\/OrderCycleHasCome.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Mail;\r\n\r\nuse App\\Models\\User;\r\nuse Illuminate\\Support\\Collection;\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass OrderCycleHasCome extends Mailable\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>private $products, $user;<\/strong>\r\n\r\n<strong>    public function __construct(Collection $products, User $user)<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $this-&gt;products = $products;<\/strong>\r\n<strong>        $this-&gt;user = $user;<\/strong>\r\n<strong>    }<\/strong>\r\n\r\n<strong>    public function build()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $from = 'info@example.com';<\/strong>\r\n<strong>        $app_name = config('app.name');<\/strong>\r\n\r\n<strong>        return $this<\/strong>\r\n<strong>            -&gt;to($this-&gt;user-&gt;email)<\/strong>\r\n<strong>            -&gt;from($from, $app_name)<\/strong>\r\n<strong>            -&gt;subject('\u65b0\u7740\u5546\u54c1\u306e\u3054\u7d39\u4ecb')<\/strong>\r\n<strong>            -&gt;view('emails.order_cycle_has_come')<\/strong>\r\n<strong>            -&gt;with([<\/strong>\r\n<strong>                'products' =&gt; $this-&gt;products,<\/strong>\r\n<strong>                'user' =&gt; $this-&gt;user,<\/strong>\r\n<strong>                'app_name' =&gt; $app_name<\/strong>\r\n<strong>            ]);<\/strong>\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u6b21\u306b\u3001\u30e1\u30fc\u30eb\u672c\u6587\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u3059\u3002<\/p>\n<p><strong>resources\/views\/emails\/order_cycle_has_come.blade.php<\/strong><\/p>\n<pre><strong>&lt;strong&gt;{{ $user-&gt;name }} \u69d8&lt;\/strong&gt;\u3001\u3044\u3064\u3082\u5f53\u5e97\u3067\u3054\u8cfc\u5165\u3044\u305f\u3060\u304d\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01&lt;br&gt;&lt;br&gt;<\/strong>\r\n\r\n<strong>\u672c\u65e5\u306f &lt;strong&gt;{{ $user-&gt;name }} \u69d8&lt;\/strong&gt; \u306b\u304a\u3059\u3059\u3081\u306e\u65b0\u7740\u5546\u54c1\u3092\u3054\u7d39\u4ecb\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059 &amp;#x1F6CD;&lt;br&gt;&lt;br&gt;<\/strong>\r\n\r\n<strong>&lt;hr&gt;<\/strong>\r\n\r\n<strong>@foreach($products as $product)<\/strong>\r\n<strong>    &lt;a href=\"{{ url('products\/'. $product-&gt;id) }}\"&gt;{{ $loop-&gt;iteration }}. {{ $product-&gt;name }}&lt;\/a&gt;&lt;br&gt;<\/strong>\r\n<strong>    &lt;img src=\"https:\/\/via.placeholder.com\/360x180?text=Test%20Image\"&gt;&lt;br&gt;<\/strong>\r\n<strong>    &lt;hr&gt;<\/strong>\r\n<strong>@endforeach<\/strong>\r\n\r\n<strong>&lt;br&gt;<\/strong>\r\n\r\n<strong>\u3010{{ $app_name }}\u3011&lt;br&gt;<\/strong>\r\n<strong>&lt;a href=\"{{ url('\/') }}\"&gt;{{ url('\/') }}&lt;\/a&gt;<\/strong><\/pre>\n<p>\u203b \u672c\u6765\u3001\u5e83\u544a\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u969b\u306f\u30aa\u30d7\u30c8\u30a2\u30a6\u30c8\u306e\u65b9\u6cd5\u3092\u8a18\u8ff0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u8a73\u3057\u304f\u306f\u3001<a href=\"#opt-in-out\">\u3061\u306a\u307f\u306b\uff1a \u7279\u5b9a\u96fb\u5b50\u30e1\u30fc\u30eb\u6cd5<\/a> \u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u30b3\u30de\u30f3\u30c9\u3092\u3064\u304f\u308b<\/h2>\n<p>\u6bce\u56de\u6bce\u56de\u624b\u52d5\u3067\u306f\u3081\u3093\u3069\u3046\u3067\u3059\u306e\u3067\u3001<code>Laravel<\/code>\u306b\u72ec\u81ea\u306e\u30b3\u30de\u30f3\u30c9\u3092\u3064\u304f\u308a\u3001\u305d\u306e\u30b3\u30de\u30f3\u30c9\u3092<code>crontab<\/code>\u3067\u5b9a\u671f\u7684\u306b\u81ea\u52d5\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u3057\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:command SendDmCommand<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u306e\u3067\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002\u30b3\u30de\u30f3\u30c9\u306f\u4f5c\u3063\u305f\u3060\u3051\u3067\u306f\u5229\u7528\u3067\u304d\u307e\u305b\u3093\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u3066<code>Laravel<\/code>\u3078\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Console\\Commands;\r\n\r\n<strong>use App\\Mail\\OrderCycleHasCome;<\/strong>\r\n<strong>use App\\Models\\Order;<\/strong>\r\n<strong>use App\\Models\\OrderSummary;<\/strong>\r\n<strong>use App\\Models\\Product;<\/strong>\r\nuse Illuminate\\Console\\Command;\r\n\r\nclass SendDmCommand extends Command\r\n{\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>protected $signature = 'send:dm';<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>protected $description = 'Send DM';<\/strong>\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>public function handle()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $today = today();<\/strong>\r\n<strong>        $summaries = OrderSummary::where('dm_sending_date', $today)-&gt;get();<\/strong>\r\n\r\n<strong>        foreach($summaries as $summary) {<\/strong>\r\n\r\n<strong>            $user_id = $summary-&gt;user_id;<\/strong>\r\n<strong>            $orders = Order::where('user_id', $user_id)-&gt;get();<\/strong>\r\n<strong>            $category_ids = $orders-&gt;pluck('product.category_id')-&gt;unique();<\/strong>\r\n<strong>            $product_ids = $orders-&gt;pluck('product_id')-&gt;unique();<\/strong>\r\n\r\n<strong>            $products = Product::whereIn('category_id', $category_ids)<\/strong>\r\n<strong>                -&gt;whereNotIn('id', $product_ids)<\/strong>\r\n<strong>                -&gt;latest()<\/strong>\r\n<strong>                -&gt;take(3)<\/strong>\r\n<strong>                -&gt;get();<\/strong>\r\n<strong>            \\Mail::send(new OrderCycleHasCome($products, $summary-&gt;user));<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        $this-&gt;info('Done!');<\/strong>\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p><strong>app\/Console\/Kernel.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Console;\r\n\r\n<strong>use App\\Console\\Commands\\SendDmCommand;\r\n<\/strong>\r\n\/\/ \u7701\u7565\r\n\r\nclass Kernel extends ConsoleKernel\r\n{\r\n    \/\/ \u7701\u7565\r\n    protected $commands = [\r\n        <strong>SendDmCommand::class<\/strong>\r\n    ];<\/pre>\n<p>\u3053\u308c\u3067\u3001<code>php artisan send:dm<\/code>\u30b3\u30de\u30f3\u30c9\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h1 id=\"opt-in-out\">\u3061\u306a\u307f\u306b\uff1a \u7279\u5b9a\u96fb\u5b50\u30e1\u30fc\u30eb\u6cd5<\/h1>\n<p>\u306a\u304a\u3001\u73fe\u5728\u306f\u300c<strong>\u7279\u5b9a\u96fb\u5b50\u30e1\u30fc\u30eb\u6cd5<\/strong>\u300d\u306b\u3088\u3063\u3066\u5e83\u544a\u30e1\u30fc\u30eb\u3092\u9001\u4fe1\u3059\u308b\u969b\u306f\u3001<\/p>\n<ul>\n<li>\u30aa\u30d7\u30c8\u30a4\u30f3<\/li>\n<li>\u30aa\u30d7\u30c8\u30a2\u30a6\u30c8<\/li>\n<\/ul>\n<p>\u306e\u6a5f\u80fd\u304c\u4f7f\u3048\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u306e\u3067\u3054\u6ce8\u610f\u304f\u3060\u3055\u3044\u3002<br \/>\n\u8a73\u3057\u304f\u306f\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\ud83d\udcdd\u00a0<a href=\"https:\/\/blog.capilano-fw.com\/?p=5466\">\u3010Laravel\u3011\u30aa\u30d7\u30c8\u30a4\u30f3\uff0f\u30aa\u30d7\u30c8\u30a2\u30a6\u30c8\u306e\u30e1\u30fc\u30eb\u9001\u4fe1\u6a5f\u80fd<\/a><\/p>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001<code>order_summaries<\/code>\u30c6\u30fc\u30d6\u30eb\u306e<code>dm_sending_date<\/code>\u3092\uff11\u4ef6\u4eca\u65e5\u306b\u624b\u52d5\u3067\u5909\u66f4\u3057\u3001\u9001\u4fe1\u30c6\u30b9\u30c8\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u3067\u306f\u3001\u4f5c\u6210\u3057\u305f\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan send:dm<\/strong><\/pre>\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-9128\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_3.png\" alt=\"\" width=\"583\" height=\"441\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_3.png 583w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/05\/analyze_order_patterns_3-300x227.png 300w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/p>\n<p>\u306f\u3044\u2757<\/p>\n<p>\u3046\u307e\u304f\u30e1\u30fc\u30eb\u9001\u4fe1\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\n\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u203b \u81ea\u52d5\u7684\u306b\u30bf\u30a4\u30de\u30fc\u5b9f\u884c\u3059\u308b\u306b\u306f <code>crontab<\/code> \u306a\u3069\u306b<code>php artisan send:dm<\/code>\u304c\u5b9f\u884c\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h1>\u4f01\u696d\u69d8\u3078\u306e\u3054\u63d0\u6848<\/h1>\n<p>\u4eca\u56de\u306f\u300c<strong>\u8cfc\u5165\u5468\u671f<\/strong>\u300d\u3068\u300c<strong>\u8208\u5473\u306e\u3042\u308b\u30ab\u30c6\u30b4\u30ea<\/strong>\u300d\u3060\u3051\u3067\u96c6\u8a08\u3092\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u308c\u4ee5\u5916\u306b\u3082\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u96c6\u8a08\u65b9\u6cd5\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<ul>\n<li>\u5546\u54c1\u3054\u3068\u306b\u5e73\u5747\u3069\u306e\u304f\u3089\u3044\u306e\u91d1\u984d\u3092\u4f7f\u3063\u3066\u3044\u308b\u304b\u3092\u8a08\u7b97\u3057\u3001\u3088\u308a\u8fd1\u3044\u5546\u54c1\u3092\u3059\u3059\u3081\u308b<\/li>\n<li>\u304a\u5ba2\u3055\u3093\u306b\u3088\u3063\u3066\u30e9\u30a4\u30d5\u30b9\u30bf\u30a4\u30eb\u304c\u9055\u3046\u306e\u3067DM\u3092\u9001\u4fe1\u3059\u3079\u304d\u6642\u9593\u5e2f\u3092\u904e\u53bb\u30c7\u30fc\u30bf\u304b\u3089\u5272\u308a\u51fa\u3059<\/li>\n<li>\u5546\u54c1\u306b\u8272\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3057\u3001\u300c\u597d\u304d\u306a\u8272\u300d\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5546\u54c1\u3070\u304b\u308a\u3092\u304a\u3059\u3059\u3081\u3059\u308b<\/li>\n<li>\u8cfc\u5165\u5f8c\u306b\u6295\u7a3f\u3057\u305f\u30ec\u30d3\u30e5\u30fc\u5185\u5bb9\uff08\u30b9\u30bf\u30fc\u306a\u3069\uff09\u3092\u4f7f\u3063\u3066\u3001\u9006\u306b\u300c\u304a\u3059\u3059\u3081\u3059\u3079\u304d\u3067\u306a\u3044\u300d\u5546\u54c1\u3092\u5272\u308a\u51fa\u3059<\/li>\n<li>\u30d7\u30ec\u30bc\u30f3\u30c8\u7528\u3068\u3057\u3066\u8cfc\u5165\u3055\u308c\u305f\u3082\u306e\u306f\u304a\u3059\u3059\u3081\u304b\u3089\u306f\u9664\u5916\u3059\u308b<\/li>\n<\/ul>\n<p>\u306a\u3069\u306a\u3069\u3002<\/p>\n<p>\u307e\u305f\u3001\u3055\u3089\u306b\u767a\u5c55\u3055\u305b\u3066DM\u306e\u300c\u30af\u30ea\u30c3\u30af\u7387\u300d\u3084\u300c\u8cfc\u5165\u7387\u300d\u3092\u691c\u8a3c\u3057\u3001\u3088\u308a\u8cb7\u3063\u3066\u3082\u3089\u3048\u308b\u96c6\u8a08\u3092\u63a2\u3059\u306e\u3082\u3072\u3068\u3064\u306e\u624b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u305c\u3072\u3053\u3046\u3044\u3063\u305f\u30b7\u30b9\u30c6\u30e0\u3067\u8ca9\u4fc3\u3092\u304a\u8003\u3048\u306e\u5834\u5408\u306f\u3001\u304a\u554f\u3044\u5408\u308f\u305b\u304b\u3089\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002m(_ _)m<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u300c<strong>\u30d7\u30ed\u30b0\u30e9\u30e0\u3068\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u306e\u878d\u5408<\/strong>\u300d\u3092\u30c6\u30fc\u30de\u306b\u8a18\u4e8b\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u904e\u53bb\u306b\u306f\u3044\u304f\u3064\u3082\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u672c\u3092\u8cb7\u3063\u3066\u8aad\u307f\u307e\u3057\u305f\u304c\u3001\u307b\u307c\u5927\u6383\u9664\u3067\u6368\u3066\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n<p>\u305f\u3060\u3001\u305d\u306e\u4e2d\u306b\u306f\u300c<strong>\u3053\u306e\u672c\u3060\u3051\u306f\u6368\u3066\u3061\u3083\u30c0\u30e1\u3060\uff01<\/strong>\u300d\u3068\u3001\u624b\u5143\u306b\u6b8b\u3063\u3066\u3044\u308b\u3082\u306e\u304c\u3042\u308b\u306e\u3067\u307e\u305f\u8aad\u307f\u8fd4\u3057\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u306b\u3057\u3066\u3082\u3001\u305a\u3063\u3068\u6614\u306b\u8aad\u3093\u3060\u672c\u3067\u3082\u611f\u9298\u3092\u53d7\u3051\u305f\u90e8\u5206\u306f\u899a\u3048\u3066\u3044\u308b\u3082\u306e\u3067\u3059\u306d\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u3001\u30d7\u30ed\u30b0\u30e9\u30e0 \uff06 \u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u3067\u4f55\u304b\u6a5f\u80fd\u3092\u8003\u3048\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-6068 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png\" alt=\"\" width=\"226\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12.png 226w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_12-212x300.png 212w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/>\u300c\u5b6b\u5b50\u306e\u5175\u6cd5\u3082<br \/>\n\u3082\u3046\u4e00\u56de\u8aad\u3082\u3046\u304b\u306a\u3002<br \/>\n\u6226\u308f\u305a\u306b\u52dd\u3061\u305f\u3044\uff08\u7b11\uff09\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u3060\u3051\u306b\u9650\u3089\u305a\u3067\u3059\u304c\u3001\u6700\u8fd1\u306f\u6642\u4ee3\u306e\u5909\u5316\u304c\u3068\u3066\u3082\u65e9\u3044\u306e\u3067\u3001\u5e38\u306b\u81ea\u5206\u3092\u6642\u4ee3\u306b\u5408\u308f\u305b\u3066\u3044\u304b\u306a\u304d\u3083\uff01\u3068\u611f\u3058\u3066\u3044\u307e\u3059\u3002 \u305d\u3057\u3066\u3001\u305d\u308c\u306b\u95a2\u9023\u3057\u3066\u5c11\u3057 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=9122\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Laravel\u3067\u8cfc\u5165\u5c65\u6b74\u304b\u3089\u30d1\u30bf\u30fc\u30f3\u5206\u6790\u3057\u3001DM\u3092\u9001\u308b\u30b7\u30b9\u30c6\u30e0\u3092\u3064\u304f\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":9134,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[234],"class_list":["post-9122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-234"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/9122","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=9122"}],"version-history":[{"count":7,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/9122\/revisions"}],"predecessor-version":[{"id":9133,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/9122\/revisions\/9133"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/9134"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}