{"id":8746,"date":"2021-03-22T07:00:25","date_gmt":"2021-03-21T22:00:25","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=8746"},"modified":"2021-03-20T05:36:38","modified_gmt":"2021-03-19T20:36:38","slug":"%e3%80%90laravel%e3%80%91%e7%ab%b6%e5%90%88%e3%81%ae%e5%80%a4%e6%ae%b5%e3%82%92%e3%82%b9%e3%82%af%e3%83%ac%e3%82%a4%e3%83%94%e3%83%b3%e3%82%b0%e3%81%97%e3%81%a6%e8%87%aa%e7%a4%be%e8%a3%bd%e5%93%81","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=8746","title":{"rendered":"\u3010Laravel\u3011\u7af6\u5408\u306e\u5024\u6bb5\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u81ea\u793e\u88fd\u54c1\u306e\u91d1\u984d\u3092\u5909\u66f4\u3059\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593 <a href=\"https:\/\/blog.capilano-fw.com\/?p=8659\">\u3010Laravel\u3011AB\u30c6\u30b9\u30c8\u6a5f\u80fd\u3092\u3064\u304f\u308b<\/a> \u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002\u8a18\u4e8b\u5185\u306b\u3082\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u306f\u300c<strong>\u7d4c\u55b6\u8005\u7684\u306a\u8996\u70b9<\/strong>\u300d\u304b\u3089\u5fc5\u8981\u306a\u6a5f\u80fd\u3068\u3057\u3066\u6295\u7a3f\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3042\u308b<code>RPA<\/code>\uff08\u30ed\u30dc\u30c6\u30a3\u30c3\u30af\u30fb\u30d7\u30ed\u30bb\u30b9\u30fb\u30aa\u30fc\u30c8\u30e1\u30fc\u30b7\u30e7\u30f3 \u2252 \u8981\u3059\u308b\u306b\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u3088\u308b\u81ea\u52d5\u5316\uff09\u306e\u8a18\u4e8b\u3092\u8aad\u3093\u3067\u3044\u3066\u300c<strong>\u3053\u308c\u306f\u9762\u767d\u305d\u3046\uff01<\/strong>\u300d\u3068\u601d\u3063\u305f\u306e\u304c\u4eca\u56de\u306e\u30c6\u30fc\u30de\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u304c\u30fb\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u7af6\u5408\u306e\u5024\u6bb5\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u81ea\u793e\u88fd\u54c1\u306e\u91d1\u984d\u3092\u81ea\u52d5\u3067\u5909\u66f4\u3059\u308b<\/strong><\/p>\n<p>\u6a5f\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u4f8b\u3048\u3070\u300c<strong>\uff11\u65e5\u306b\uff11\u56de\u81ea\u52d5\u3067\u5024\u6bb5\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001\u305d\u306e\u91d1\u984d\u304b\u3089<\/strong><strong>\u00a010\u5186 \u5024\u5f15\u304d\u3059\u308b<\/strong>\u300d\u3068\u304b\u305d\u3046\u3044\u3046\u4f7f\u3044\u65b9\u3067\u3059\u306d\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u4eca\u56de\u306f\u300c<strong>\u7d4c\u55b6\u8005\u5411\u3051\u6a5f\u80fd<\/strong>\u300d\u306e\u7b2c\uff12\u5f3e\u3068\u3057\u3066\u3001\u300c\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0 + \u91d1\u984d\u8a2d\u5b9a\u300d\u306e\u81ea\u52d5\u5316\u3092\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u5fa1\u793e\u306e\u5f79\u306b\u7acb\u3061\u307e\u3057\u305f\u3089\u5149\u6804\u3067\u3059\ud83d\ude0a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6066 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_23.png\" alt=\"\" width=\"370\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_23.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2020\/03\/no_23-300x259.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/><\/p>\n<p style=\"text-align: center;\">\u300c\u5730\u5143\u306e\u30af\u30e9\u30d5\u30c8\u30d3\u30fc\u30eb\u3001<br \/>\n\u30a6\u30de\u30a6\u30de\u3067\u3059\ud83c\udf7a\u2728\u300d<\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 8.x<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4eca\u56de\u306f\u3001\u5e02\u8ca9\u3055\u308c\u3066\u3044\u308b\u30af\u30e9\u30d5\u30c8\u30d3\u30fc\u30eb\u306e\u4e2d\u3067\u4e00\u756a\u79c1\u304c\u597d\u304d\u306a\u300c<strong>\u30a4\u30f3\u30c9\u306e\u9752\u9b3c<\/strong>\u300d\u306e24\u7f36\u30bb\u30c3\u30c8\u3092\u984c\u6750\u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u79c1\u304c\u3053\u306e\u30d3\u30fc\u30eb\u3092\u8ca9\u58f2\u3057\u3066\u3044\u308b\u3068\u4eee\u5b9a\u3057\u3001\u67b6\u7a7a\u30b5\u30a4\u30c8\u304b\u3089\u6700\u5b89\u5024\u3092\u53d6\u5f97\uff06<strong>\u305d\u306e\u5024\u6bb5\u3088\u308a10\u5186\u5b89\u304f\u3057\u3066\u30c7\u30fc\u30bf\u4fdd\u5b58<\/strong>\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u306a\u304a\u3001\u3082\u3061\u308d\u3093\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u5148\u306e\u30b5\u30a4\u30c8\u306f\u5546\u54c1\u306b\u3088\u3063\u3066\u9055\u3063\u3066\u304d\u307e\u3059\u306e\u3067\u3001\u305d\u308c\u305e\u308c\u300c<strong>\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u7528\u30af\u30e9\u30b9<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u6c4e\u7528\u7684\u306b\u5b9f\u88c5\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b\u3061\u306a\u307f\u306b\u3001\u30a4\u30f3\u30c9\u306e\u9752\u9b3c\u306f\u3053\u3061\u3089\u3067\u3059\u3002<\/p>\n<p>\u2193\u3000\u2193\u3000\u2193<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8747\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_1.png\" alt=\"\" width=\"360\" height=\"480\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_1.png 360w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_1-225x300.png 225w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><\/p>\n<p>\uff11\u7f36280\u5186\u3050\u3089\u3044\u3067\u3059\u304c\u3001350\u5186\u3067\u3082\u8ff7\u308f\u305a\u8cb7\u3063\u3066\u3057\u307e\u3046\u3068\u601d\u3044\u307e\u3059\uff08\u7b11\uff09cheers! \ud83c\udf7a\u2728<\/p>\n<h1>\u5546\u54c1\u30c6\u30fc\u30d6\u30eb\uff06\u30e2\u30c7\u30eb\u3092\u7528\u610f\u3059\u308b<\/h1>\n<p>\u307e\u305a\u306f\u306f\u3058\u3081\u306b\u3001\u300c<strong>\u81ea\u793e\u88fd\u54c1\u30c7\u30fc\u30bf<\/strong>\u300d\u3092\u7ba1\u7406\u3059\u308b<code>items<\/code>\u30c6\u30fc\u30d6\u30eb\u3068\u305d\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\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:model Item -m<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3068\u30e2\u30c7\u30eb\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u3001\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>database\/migrations\/****_**_**_******_create_items_table.php<\/strong><\/p>\n<pre>\/\/ \u7701\u7565\r\n\r\npublic function up()\r\n{\r\n    <strong>Schema::create('items', 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;unsignedInteger('price')-&gt;comment('\u5024\u6bb5');<\/strong>\r\n<strong>        $table-&gt;string('scraping_class')-&gt;comment('\u30b9\u30af\u30ec\u30d4\u30f3\u30b0\u7528\u30af\u30e9\u30b9\u540d');<\/strong>\r\n<strong>        $table-&gt;string('scraping_url')-&gt;comment('\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u5148URL');<\/strong>\r\n<strong>        $table-&gt;dateTime('scraped_at')-&gt;comment('\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u305f\u65e5\u6642');<\/strong>\r\n<strong>        $table-&gt;timestamps();<\/strong>\r\n<strong>    });<\/strong>\r\n}\r\n\r\n\/\/ \u7701\u7565<\/pre>\n<h1>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b<\/h1>\n<p>\u6b21\u306b\u3001\u958b\u767a\u3059\u308b\u969b\u306b\u4f55\u3082\u30c7\u30fc\u30bf\u304c\u306a\u3044\u3068\u4e0d\u4fbf\u3067\u3059\u306e\u3067\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u5fc5\u8981\u306a\u30c7\u30fc\u30bf\u306f\uff11\u4ef6\u3060\u3051\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:seed ItemsTableSeeder<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>Seeder<\/code>\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><strong>database\/seeders\/ItemsTableSeeder.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace Database\\Seeders;\r\n\r\n<strong>use App\\Models\\Item;<\/strong>\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass ItemsTableSeeder extends Seeder\r\n{\r\n<strong>    public function run()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $item = new Item();<\/strong>\r\n<strong>        $item-&gt;name = '\u30a4\u30f3\u30c9\u306e\u9752\u9b3c';<\/strong>\r\n<strong>        $item-&gt;price = 8000;<\/strong>\r\n<strong>        $item-&gt;scraping_class = 'App\\Scrapes\\LowestPriceScrape'; \/\/ \u5f8c\u3067\u3064\u304f\u308a\u307e\u3059<\/strong>\r\n<strong>        $item-&gt;scraping_url = 'http:\/\/l8x.test\/scraping_page'; \/\/ \u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308bURL<\/strong>\r\n<strong>        $item-&gt;scraped_at = now();<\/strong>\r\n<strong>        $item-&gt;save();<\/strong>\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u5909\u66f4\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001<code>Laravel<\/code>\u5074\u3078\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace Database\\Seeders;\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        <strong>$this-&gt;call(ItemsTableSeeder::class); \/\/ \ud83d\udc48 \u3053\u3053\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u4eca\u306e\u72b6\u614b\u3067\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066DB\u3092\u518d\u69cb\u7bc9\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u5b9f\u884c\u304c\u5b8c\u4e86\u3059\u308b\u3068\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8757\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_2.png\" alt=\"\" width=\"640\" height=\"177\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_2.png 640w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_2-300x83.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<h1>\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u7528\u306e\u30af\u30e9\u30b9\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u7d9a\u3044\u3066\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u7528\u306e\u30af\u30e9\u30b9\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30af\u30e9\u30b9\u3092\u72ec\u81ea\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u3001\u4ed6\u306e\u3069\u3093\u306a\u30b5\u30a4\u30c8\u306b\u3082\u5bfe\u5fdc\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u67b6\u7a7a\u306e\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u5148\u30da\u30fc\u30b8\u3092\u3064\u304f\u308b<\/h2>\n<p>\u5b9f\u969b\u306b\u30af\u30e9\u30b9\u3092\u4f5c\u308b\u524d\u306b\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u5148\u306e\u67b6\u7a7a\u306e\u8ca9\u58f2\u30da\u30fc\u30b8\u3092\u3064\u304f\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u306f\u30eb\u30fc\u30c8\u3067\u3059\u3002<\/p>\n<p><strong>routes\/web.php<\/strong><\/p>\n<pre><strong>Route::get('scraping_page', function(){ return view('scraping_page'); });<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u30d3\u30e5\u30fc\u3067\u3059\u3002<\/p>\n<p><strong>resources\/views\/scraping_page.blade.php<\/strong><\/p>\n<pre><strong>&lt;html&gt;<\/strong>\r\n<strong>&lt;head&gt;<\/strong>\r\n<strong>    &lt;title&gt;\u30a4\u30f3\u30c9\u306e\u9752\u9b3c 350ml \u00d724\u7f36&lt;\/title&gt;<\/strong>\r\n<strong>&lt;\/head&gt;<\/strong>\r\n<strong>&lt;body&gt;<\/strong>\r\n<strong>    &lt;h1&gt;\u30a4\u30f3\u30c9\u306e\u9752\u9b3c 350ml \u00d724\u7f36&lt;\/h1&gt;<\/strong>\r\n<strong>    &lt;table&gt;<\/strong>\r\n<strong>        &lt;tr&gt;<\/strong>\r\n<strong>            &lt;td class=\"store_name\"&gt;\u5546\u5e97 A&lt;\/td&gt;<\/strong>\r\n<strong>            &lt;td class=\"price\"&gt;\u00a56,670&lt;\/td&gt;<\/strong>\r\n<strong>        &lt;\/tr&gt;<\/strong>\r\n<strong>        &lt;tr&gt;<\/strong>\r\n<strong>            &lt;td class=\"store_name\"&gt;\u5546\u5e97 B&lt;\/td&gt;<\/strong>\r\n<strong>            &lt;td class=\"price\"&gt;\u00a56,680&lt;\/td&gt;<\/strong>\r\n<strong>        &lt;\/tr&gt;<\/strong>\r\n<strong>        &lt;tr&gt;<\/strong>\r\n<strong>            &lt;td class=\"store_name\"&gt;\u5546\u5e97 C&lt;\/td&gt;<\/strong>\r\n<strong>            &lt;td class=\"price\"&gt;\u00a57,040&lt;\/td&gt;<\/strong>\r\n<strong>        &lt;\/tr&gt;<\/strong>\r\n<strong>    &lt;\/table&gt;<\/strong>\r\n<strong>&lt;\/body&gt;<\/strong>\r\n<strong>&lt;\/html&gt;<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u300c<strong>http:\/\/******\/scraping_page<\/strong>\u300d\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8751\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_3.png\" alt=\"\" width=\"427\" height=\"171\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_3.png 427w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_3-300x120.png 300w\" sizes=\"auto, (max-width: 427px) 100vw, 427px\" \/><\/p>\n<h2>\u5c02\u7528\u30af\u30e9\u30b9\u3092\u3064\u304f\u308b<\/h2>\n<p>\u3067\u306f\u3001\u5148\u307b\u3069\u306e\u67b6\u7a7a\u30da\u30fc\u30b8\u304b\u3089\u30c7\u30fc\u30bf\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u30af\u30e9\u30b9\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3059\u304c\u3001\u300c<strong>\u3084\u308a\u305f\u3044\u3053\u3068<\/strong>\u300d\u3067\u3082\u66f8\u3044\u305f\u3088\u3046\u306b\u3069\u3093\u306a\u30d1\u30bf\u30fc\u30f3\u3067\u3082\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u305f\u3044\u306e\u3067\u3001\u4eca\u56de\u306f\u300c<strong>\u62bd\u8c61\u30af\u30e9\u30b9<\/strong>\u300d\u3092\u3064\u304b\u3063\u3066\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<p>\u62bd\u8c61\u30af\u30e9\u30b9\u3068\u306f\u3001\u3068\u3066\u3082\u30b7\u30f3\u30d7\u30eb\u306b\u8a00\u3046\u3068\u300c\u30af\u30e9\u30b9\u306e\u3082\u3068\u300d\u306e\u3053\u3068\u3067\u3001\u30e1\u30ea\u30c3\u30c8\u306e\uff11\u3064\u306b\u3001\u5fc5\u8981\u306a<strong>\u30e1\u30bd\u30c3\u30c9\u3092\u30bb\u30c3\u30c8\u3057\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3001\u3064\u307e\u308a\u30bb\u30c3\u30c8\u306e\u3057\u5fd8\u308c\u304c\u306a\u304f\u306a\u308b\u3068\u3044\u3046\u70b9<\/strong>\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p><strong>app\/Scrapes\/BaseScrape.php<\/strong><\/p>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Scrapes;<\/strong>\r\n\r\n<strong>use App\\Models\\Item;<\/strong>\r\n<strong>use Illuminate\\Support\\Facades\\Http;<\/strong>\r\n\r\n<strong>abstract class BaseScrape {<\/strong>\r\n\r\n<strong>    private $url;<\/strong>\r\n\r\n<strong>    abstract public function execute(); \/\/ \ud83d\udc48 \u3053\u3053\u306f\u7d99\u627f\u5148\u3067\u5fc5\u305a\u5b9a\u7fa9\u3057\u306a\u3044\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059<\/strong>\r\n\r\n<strong>    public function setUrl($url) {<\/strong>\r\n\r\n<strong>        $this-&gt;url = $url;<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>    protected function getContent() {<\/strong>\r\n\r\n<strong>        $url = $this-&gt;url;<\/strong>\r\n<strong>        $response = Http::get($url);<\/strong>\r\n<strong>        return $response-&gt;body();<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001<code>BaseScrape<\/code>\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9<code>LowestPriceScrape<\/code>\u3067\u3059\u3002<\/p>\n<p><strong>app\/Scrapes\/LowestPriceScrape.php<\/strong><\/p>\n<pre><strong>&lt;?php<\/strong>\r\n\r\n<strong>namespace App\\Scrapes;<\/strong>\r\n\r\n<strong>class LowestPriceScrape extends BaseScrape {<\/strong>\r\n\r\n<strong>    public function execute()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $content = $this-&gt;getContent();<\/strong>\r\n<strong>        $pattern = '|&lt;td class=\"price\"&gt;\u00a5([^&lt;]+)&lt;\/td&gt;|';<\/strong>\r\n\r\n<strong>        if(preg_match_all($pattern, $content, $matches)) {<\/strong>\r\n\r\n<strong>            $prices = array_map(function($price_text){<\/strong>\r\n\r\n<strong>                return (int) filter_var($price_text, FILTER_SANITIZE_NUMBER_INT);<\/strong>\r\n\r\n<strong>            }, $matches[1]);<\/strong>\r\n\r\n<strong>            return min($prices);<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return null;<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u304c\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>$scraping = new \\App\\Scrapes\\LowestPriceScrape();<\/strong>\r\n<strong>$scraping-&gt;setUrl('http:\/\/l8x.test\/scraping_page');<\/strong>\r\n<strong>$lowest_price = $scraping-&gt;execute();<\/strong><\/pre>\n<h1>\u81ea\u52d5\u5b9f\u884c\u3059\u308b\u30b3\u30de\u30f3\u30c9\u3092\u3064\u304f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9a\u671f\u7684\u306b\u30bf\u30a4\u30de\u30fc\u5b9f\u884c\u3059\u308b\u305f\u3081\u306e\u72ec\u81ea\u30b3\u30de\u30f3\u30c9\u3092\u3064\u304f\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:command ScrapingCommand<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<p><strong>app\/Console\/Commands\/ScrapingCommand.php<\/strong><\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Console\\Commands;\r\n\r\n<strong>use App\\Models\\Item;<\/strong>\r\n<strong>use App\\Scrapes\\BaseScrape;<\/strong>\r\n<strong>use App\\Scrapes\\LowestPriceScrape;<\/strong>\r\nuse Illuminate\\Console\\Command;\r\n\r\nclass ScrapingCommand extends Command\r\n{\r\n    <strong>protected $signature = 'scraping';<\/strong>\r\n<strong>    protected $description = 'Scrape external website regularly';<\/strong>\r\n\r\n<strong>    public function handle()<\/strong>\r\n<strong>    {<\/strong>\r\n<strong>        $result = false;<\/strong>\r\n<strong>        $item = Item::oldest('scraped_at')-&gt;first(); \/\/ \u4e00\u756a\u524d\u306b\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u53d6\u5f97<\/strong>\r\n<strong>        $scraping_class = $item-&gt;scraping_class;<\/strong>\r\n\r\n<strong>        if(class_exists($scraping_class)) { \/\/ \u30af\u30e9\u30b9\u304c\u5b58\u5728\u3057\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af<\/strong>\r\n\r\n<strong>            $scraping = new $scraping_class();<\/strong>\r\n\r\n<strong>            if($scraping instanceof BaseScrape) { \/\/ \u6b63\u3057\u3044\u30af\u30e9\u30b9\u304b\u30c1\u30a7\u30c3\u30af<\/strong>\r\n\r\n<strong>                $scraping = new LowestPriceScrape();<\/strong>\r\n<strong>                $scraping-&gt;setUrl($item-&gt;scraping_url);<\/strong>\r\n<strong>                $lowest_price = $scraping-&gt;execute();<\/strong>\r\n\r\n<strong>                $item-&gt;price = $lowest_price - 10; \/\/ 10\u5186\u5b89\u304f\u3059\u308b<\/strong>\r\n<strong>                $result = $item-&gt;save();<\/strong>\r\n\r\n<strong>            }<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        if($result === true) {<\/strong>\r\n\r\n<strong>            $this-&gt;info('Done!');<\/strong>\r\n\r\n<strong>        } else {<\/strong>\r\n\r\n<strong>            $this-&gt;error('Failed...');<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u3001<code>php artisan scraping<\/code>\u3092\u5b9f\u884c\u3059\u308b\u3068\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u304c\u5b9f\u884c\u3055\u308c\u3001\u5024\u6bb5\u304c\u81ea\u52d5\u3067\u66f4\u65b0\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u3053\u306e\u307e\u307e\u3067\u306f\u30b3\u30de\u30f3\u30c9\u306f\u5b9f\u884c\u3067\u304d\u306a\u3044\u306e\u3067<code>Laravel<\/code>\u5074\u306b\u767b\u9332\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\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\\ScrapingCommand;<\/strong>\r\n\r\n\/\/ \u7701\u7565\r\n\r\nclass Kernel extends ConsoleKernel\r\n{\r\n    protected $commands = [\r\n        <strong>ScrapingCommand::class \/\/ \ud83d\udc48 \u3053\u3053\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f<\/strong>\r\n    ];<\/pre>\n<h1>\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u2757<\/p>\n<p>\u307e\u305a\u5148\u306b\u73fe\u5728\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u300c<strong>\u30a4\u30f3\u30c9\u306e\u9752\u9b3c<\/strong>\u300d\u304c\u3044\u304f\u3089\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8760\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_4.png\" alt=\"\" width=\"500\" height=\"270\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_4.png 500w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_4-300x162.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p><strong>8,000\u5186 <\/strong>\u3067\u3059\u306d\u3002<\/p>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u3046\u307e\u304f\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\uff06\u5024\u6bb5\u5909\u66f4\u304c\u3067\u304d\u308b\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre><strong>php artisan scraping<\/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-8759\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2021\/03\/laravel_auto_pricing_5.png\" alt=\"\" width=\"500\" height=\"270\" \/><\/p>\n<p>\u306f\u3044\u2757<br \/>\n\uff08\u6700\u5b89\u5024 &#8211; 10\u5186\uff09\u306e<code>6,660\u5186<\/code>\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u6210\u529f\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u3042\u3068\u306f\u3001\u3053\u306e\u30b3\u30de\u30f3\u30c9\u3092<code>crontab<\/code>\u3067\u5b9a\u671f\u5b9f\u884c\u3059\u308c\u3070\u5b9a\u671f\u7684\u306b\u81ea\u52d5\u66f4\u65b0\u3067\u304d\u307e\u3059\ud83d\udc4d<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3067\u53d6\u5f97\u3057\u305f\u91d1\u984d\u3092\u4f7f\u3063\u3066\u81ea\u52d5\u7684\u306b\u4fa1\u683c\u8a2d\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u3061\u306a\u307f\u306b\u3001\u5f53\u521d\u306f\u6709\u540d\u30b5\u30a4\u30c8\u300c<strong>\u4fa1\u683c.com<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u3064\u3082\u308a\u3067\u3057\u305f\u304c\u3001\u3069\u3046\u3084\u3089\u5229\u7528\u898f\u7d04\u306b\u5f15\u3063\u304b\u304b\u308b\u3088\u3046\u3067\u3057\u305f\u306e\u3067\u9014\u4e2d\u3067\u67b6\u7a7a\u306e\u30da\u30fc\u30b8\u3092\u4f7f\u3046\u3088\u3046\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u307e\u305f\u3001\u4eca\u56de\u958b\u767a\u3057\u305f\u5185\u5bb9\u3092\u62e1\u5f35\u3059\u308b\u30a2\u30a4\u30c7\u30a2\u3068\u3057\u3066\u3001\u4eca\u56de\u306f\u5168\u306610\u5186\u5f15\u304d\u3067\u3057\u305f\u304c\u3001<code>items<\/code>\u30c6\u30fc\u30d6\u30eb\u306b<code>discount_amount<\/code>\u3068\u3044\u3046\u9805\u76ee\u3092\u7528\u610f\u3057\u3001\u3044\u304f\u3089\u5024\u5f15\u304d\u3059\u308b\u304b\u3092\u500b\u5225\u30c7\u30fc\u30bf\u3067\u5909\u66f4\u3057\u3066\u3082\u9762\u767d\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u307e\u305f\u3001\u5b9f\u969b\u306e\u904b\u7528\u3067\u306f\u5168\u304f\u540c\u3058\u5546\u54c1\u3067\u306a\u304f\u3068\u3082\u300c<strong>\u7af6\u5408\u306e\u4f3c\u305f\u5225\u306e\u5546\u54c1<\/strong>\u300d\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u304a\u3044\u3066\u3001\u5c11\u3057\u3060\u3051\u5b89\u304f\u3059\u308b\u3068\u304b\u3001\u306a\u3093\u306a\u3089\u682a\u4fa1\u3084\u91d1\u306e\u4fa1\u683c\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u308d\u3044\u308d\u306a\u3053\u3068\u304c\u3067\u304d\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u5922\u306f\u5e83\u304c\u308b\u3070\u304b\u308a\u3067\u3059\u306d\ud83d\udc4d<\/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-4445 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png\" alt=\"\" width=\"370\" height=\"310\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2.png 370w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_2-300x251.png 300w\" sizes=\"auto, (max-width: 370px) 100vw, 370px\" \/>\u300c\u6700\u8fd1\u3084\u3063\u3068\u30d9\u30fc\u30b9\u97f3\u304c<br \/>\n\u805e\u304d\u53d6\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u3002<br \/>\n\u30d9\u30f3\u30d9\u30f3\u266a\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u306e\u9593 \u3010Laravel\u3011AB\u30c6\u30b9\u30c8\u6a5f\u80fd\u3092\u3064\u304f\u308b \u3068\u3044\u3046\u8a18\u4e8b\u3092\u516c\u958b\u3057\u307e\u3057\u305f\u3002\u8a18\u4e8b\u5185\u306b\u3082\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u308c\u306f\u300c\u7d4c\u55b6\u8005\u7684\u306a\u8996\u70b9\u300d\u304b\u3089\u5fc5\u8981\u306a\u6a5f\u80fd\u3068\u3057\u3066\u6295\u7a3f\u3057 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=8746\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010Laravel\u3011\u7af6\u5408\u306e\u5024\u6bb5\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u81ea\u793e\u88fd\u54c1\u306e\u91d1\u984d\u3092\u5909\u66f4\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":8804,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[145,232,194],"class_list":["post-8746","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-cron","tag-rpa","tag-194"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8746","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=8746"}],"version-history":[{"count":11,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8746\/revisions"}],"predecessor-version":[{"id":8802,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/8746\/revisions\/8802"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/8804"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8746"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8746"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}