{"id":4656,"date":"2019-09-19T04:39:25","date_gmt":"2019-09-18T19:39:25","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=4656"},"modified":"2019-09-19T04:39:25","modified_gmt":"2019-09-18T19:39:25","slug":"%e3%80%90laravel%e3%80%91factory%e3%81%a7%e7%8b%ac%e8%87%aa%e3%81%ab%e5%95%86%e5%93%81%e3%81%ae%e3%83%86%e3%82%b9%e3%83%88%e3%83%87%e3%83%bc%e3%82%bf%e3%82%92%e7%94%a8%e6%84%8f%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=4656","title":{"rendered":"\u3010Laravel\u3011Factory\u3067\u72ec\u81ea\u306b\u5546\u54c1\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u306f<code>Laravel<\/code>\u306b\u9650\u3089\u305a\u3067\u3059\u304c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u69cb\u7bc9\u3059\u308b\u306b\u5f53\u305f\u3063\u3066\u591a\u304f\u306e\u5834\u5408\u3067\u3042\u308b\u3068\u4fbf\u5229\u3060\u306a\u3001\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u304c\u3001<strong>\u300c\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u300d<\/strong>\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u30c6\u30b9\u30c8\u30e6\u30fc\u30b6\u30fc\u3092\u4f55\u4eba\u304b\u767b\u9332\u3057\u3066\u304a\u3044\u3066\u30ed\u30b0\u30a4\u30f3\u6a5f\u80fd\u3092\u30c6\u30b9\u30c8\u3057\u305f\u308a\u3001\u53d6\u308a\u6271\u3063\u3066\u3044\u308b\u5546\u54c1\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4f5c\u3063\u3066\u691c\u7d22\u304c\u3046\u307e\u304f\u3044\u304f\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3066\u307f\u305f\u308a\u3068\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b\u3053\u3068\u3067\u958b\u767a\u3092\u52b9\u7387\u7684\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001<code>Laravel<\/code>\u3067\u306f\u3053\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\u306b\u306f<a href=\"https:\/\/github.com\/fzaninotto\/Faker\">fzaninotto\/Faker<\/a>\u3068\u3044\u3046\u6709\u540d\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3063\u3066\u3044\u3066\u3001\u7279\u5225\u4f55\u3082\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u306a\u304f\u3066\u3082\u305d\u306e\u307e\u307e\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<p>\u305f\u3060\u3057\u3001<code>Faker<\/code>\u306f\u540d\u524d\u3084\u4f4f\u6240\u306a\u3069\u3088\u304f\u4f7f\u3046\u30c7\u30fc\u30bf\u306b\u306f\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3082\u306e\u306e\uff08\u3057\u304b\u3082\u65e5\u672c\u8a9eOK\u306e\u3082\u306e\u3082\u3042\u308a\u307e\u3059\uff09\u3001\u3084\u306f\u308a\u72ec\u81ea\u3067\u4f5c\u3089\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3082\u306e\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\uff01<\/p>\n<p>\u4eca\u56de\u306f\u3001<code>Faker<\/code>\u3092\u62e1\u5f35\u3057\u3066\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u306e\u304a\u5f79\u306b\u7acb\u3066\u308b\u3068\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>&nbsp;<\/p>\n<p><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\" \/><\/p>\n<p><strong>\u958b\u767a\u74b0\u5883\uff1a<\/strong> Laravel 6.0<\/p>\n<h1>\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u4eca\u56de\u306f\u3001<code>Faker<\/code>\u3092\u4f7f\u3063\u3066<strong>\u300cDIY\u3084\u5de5\u5177\u300d<\/strong>\u306e\u5546\u54c1\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>\u203b\u30c7\u30fc\u30bf\u53d6\u5f97\u306f<a href=\"https:\/\/developer.yahoo.co.jp\/webapi\/shopping\/shopping\/v1\/itemsearch.html\" target=\"_blank\" rel=\"noopener noreferrer\">Yahoo \u30b7\u30e7\u30c3\u30d4\u30f3\u30b0\u306e\u5546\u54c1\u691c\u7d22API<\/a>\u3092\u4f7f\u3046\u306e\u3067\u3001\u30ab\u30c6\u30b4\u30eaID\u3092\u5909\u66f4\u3059\u308c\u3070\u304a\u597d\u304d\u306a\u5546\u54c1\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h1>\u524d\u63d0\u3068\u3057\u3066<\/h1>\n<p>\u4e0a\u306e\u9805\u76ee\u3067\u3082\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u4eca\u56de\u306e\u30b3\u30fc\u30c9\u3067\u306f<code>Yahoo\u30b7\u30e7\u30c3\u30d4\u30f3\u30b0API<\/code>\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066\u5b9f\u88c5\u3057\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u3001<a href=\"https:\/\/blog.capilano-fw.com\/?p=4259\" target=\"_blank\" rel=\"noopener noreferrer\">\u30d0\u30fc\u30b3\u30fc\u30c9\u30fb\u30b9\u30ad\u30e3\u30ca\u30fc\u3067IBSN\u3092\u8aad\u307f\u53d6\u3063\u3066\u672c\u306e\u5165\u8377\u51e6\u7406\u3092\u3059\u308b<\/a>\u306e<strong>\u300c\u6e96\u5099\u3059\u308b\u300d<\/strong>\u3092\u53c2\u8003\u306b\u3057\u3066<code>Client ID<\/code>\u3092\u53d6\u5f97\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u53d6\u5f97\u3057\u305f<code>Client ID<\/code>\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>.env<\/code>\u306b\u8ffd\u52a0\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>YAHOO_APPID=\uff08\u3042\u306a\u305f\u306eClient ID\uff09<\/strong><\/pre>\n<p>\u3067\u306f\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3057\u3087\u3046\uff01<\/p>\n<h1>\u5546\u54c1\u30c7\u30fc\u30bf\u306e\u30c6\u30fc\u30d6\u30eb\u3001\u30e2\u30c7\u30eb\u3092\u7528\u610f\u3059\u308b<\/h1>\n<p>\u307e\u305a\u306f\u3001\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u767b\u9332\u3059\u308b\u305f\u3081\u306eDB\u30c6\u30fc\u30d6\u30eb\u3068\u3001\u305d\u306e\u7ba1\u7406\u3092\u3059\u308b\u30e2\u30c7\u30eb\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 Product -m<\/strong><\/pre>\n<p>\u3053\u308c\u3067\u3001\u30e2\u30c7\u30eb<code>Product<\/code>\u3068<code>products<\/code>\u30c6\u30fc\u30d6\u30eb\u306e\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u304c\u4f5c\u6210\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u4f5c\u6210\u3055\u308c\u305f<code>database\/migrations\/****_**_**_******_create_products_table.php<\/code>\u3092\u958b\u3044\u3066<code>up()<\/code>\u3092\u6b21\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>public function up()\r\n{\r\n    <strong>Schema::create('products', function (Blueprint $table) {<\/strong>\r\n<strong>        $table-&gt;bigIncrements('id');<\/strong>\r\n<strong>        $table-&gt;string('name')-&gt;comment('\u5546\u54c1\u540d');<\/strong>\r\n<strong>        $table-&gt;string('code')-&gt;comment('\u5546\u54c1\u30b3\u30fc\u30c9');<\/strong>\r\n<strong>        $table-&gt;integer('price')-&gt;comment('\u4fa1\u683c');<\/strong>\r\n<strong>        $table-&gt;timestamps();<\/strong>\r\n<strong>    });<\/strong>\r\n}<\/pre>\n<p>\u5909\u66f4\u304c\u7d42\u308f\u3063\u305f\u3089\u3001\u30de\u30a4\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan migrate<\/strong><\/pre>\n<p>\u5b9f\u884c\u3059\u308b\u3068\u30c6\u30fc\u30d6\u30eb\u3053\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4657\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_1.png\" alt=\"\" width=\"355\" height=\"275\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_1.png 355w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_1-300x232.png 300w\" sizes=\"auto, (max-width: 355px) 100vw, 355px\" \/><\/p>\n<h1>Faker\u306e\u72ec\u81ea\u30d7\u30ed\u30d0\u30a4\u30c0\u30fc\u3092\u4f5c\u6210\u3059\u308b<\/h1>\n<h2>\u5c02\u7528\u306eServiceProvider\u3092\u3064\u304f\u308b<\/h2>\n<pre><strong>php artisan make:provider FakerServiceProvider<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>app\/Providers\/FakerServiceProvider.php<\/code>\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u4e2d\u8eab\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Providers;\r\n\r\nuse App\\Faker\\Product;\r\nuse Faker\\Factory as FakerFactory;\r\nuse Faker\\Generator as FakerGenerator;\r\nuse Illuminate\\Support\\ServiceProvider;\r\n\r\nclass FakerServiceProvider extends ServiceProvider\r\n{\r\n    \/**\r\n     * Register services.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function register()\r\n    {\r\n        <strong>$this-&gt;app-&gt;singleton(FakerGenerator::class, function ($app) {<\/strong>\r\n\r\n<strong>            $faker = FakerFactory::create($app['config']-&gt;get('app.faker_locale', 'en_US'));<\/strong>\r\n<strong>            $faker-&gt;addProvider(new Product($faker));<\/strong>\r\n<strong>            return $faker;<\/strong>\r\n\r\n<strong>        });<\/strong>\r\n    }\r\n\r\n    \/**\r\n     * Bootstrap services.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function boot()\r\n    {\r\n        \/\/\r\n    }\r\n}<\/pre>\n<p>\u5909\u66f4\u3057\u305f\u3089\u3001\u3053\u306e<code>ServiceProvider<\/code>\u3092<code>Laravel<\/code>\u3078\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n<pre>'providers' =&gt; [\r\n\r\n    \/\/ \u7701\u7565\r\n\r\n    <strong>App\\Providers\\FakerServiceProvider::class<\/strong>\r\n\r\n],<\/pre>\n<h2>Faker\u7528\u306e\u72ec\u81ea\u30af\u30e9\u30b9\u3092\u3064\u304f\u308b<\/h2>\n<p><code>FakerServiceProvider<\/code>\u3067\u306f<code>App\\Faker\\Product<\/code>\u3068\u3044\u3046\u30af\u30e9\u30b9\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u304c\u3001\u307e\u3060\u5b58\u5728\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u4f5c\u6210\u3057\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u307e\u305a\u3001<code>app\/Faker\/Product.php<\/code>\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002\uff08<code>Faker<\/code>\u30d5\u30a9\u30eb\u30c0\u3082\u7121\u3044\u306e\u3067\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\uff09<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4659\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_2.png\" alt=\"\" width=\"264\" height=\"155\" \/><\/p>\n<p>\u305d\u3057\u3066\u3001\u4e2d\u8eab\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>&lt;?php\r\n\r\nnamespace App\\Faker;\r\n\r\nuse Illuminate\\Support\\Arr;\r\n\r\nclass Product extends \\Faker\\Provider\\Base\r\n{\r\n    private $_products = [];\r\n\r\n    public function product($parameters) {\r\n\r\n        if(empty($this-&gt;_products)) {\r\n\r\n            $this-&gt;_products = <strong>$this-&gt;getProducts($parameters);<\/strong>\r\n\r\n        }\r\n\r\n        return Arr::random($this-&gt;_products);\r\n\r\n    }\r\n\r\n    <strong>private function getProducts($parameters) {<\/strong>\r\n\r\n<strong>        $parameters['appid'] = env('YAHOO_APPID');<\/strong>\r\n<strong>        $url = 'https:\/\/shopping.yahooapis.jp\/ShoppingWebService\/V1\/json\/itemSearch?'. http_build_query($parameters);<\/strong>\r\n<strong>        $json = file_get_contents($url);<\/strong>\r\n<strong>        $data = json_decode($json, true);<\/strong>\r\n\r\n<strong>        $products = [];<\/strong>\r\n<strong>        $total = intval($data['ResultSet']['totalResultsReturned']);<\/strong>\r\n\r\n<strong>        for($i = 0 ; $i &lt; $total ; $i++) {<\/strong>\r\n\r\n<strong>            $product = $data['ResultSet'][0]['Result'][$i];<\/strong>\r\n\r\n<strong>            $products[] = [<\/strong>\r\n<strong>                'name' =&gt; $product['Name'],<\/strong>\r\n<strong>                'code' =&gt; $product['Code'],<\/strong>\r\n<strong>                'price' =&gt; $product['Price']['_value'],<\/strong>\r\n<strong>            ];<\/strong>\r\n\r\n<strong>        }<\/strong>\r\n\r\n<strong>        return $products;<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001<code>getProducts()<\/code>\u306e\u4e2d\u3067<code>Yahoo API<\/code>\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u5fc5\u8981\u306a\u60c5\u5831\u3092\u53d6\u5f97\u3001\u305d\u3057\u3066\u3001<code>Arr::random()<\/code>\u3067\u305d\u306e\u4e2d\u304b\u3089\u30e9\u30f3\u30c0\u30e0\u306b\u5546\u54c1\u30c7\u30fc\u30bf\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<h1>\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u8ffd\u52a0\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u3067\u3064\u304f\u3063\u305f<code>Faker<\/code>\u306e\u72ec\u81ea\u30d7\u30ed\u30d0\u30a4\u30c0\u30fc\u304c\u4f7f\u3048\u308b\u304b\u3069\u3046\u304b\u3092<code>Laravel<\/code>\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u6a5f\u80fd<code>Factory<\/code>\u3068<code>Seeder<\/code>\u3092\u4f7f\u3063\u3066\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>Factory\u3092\u3064\u304f\u308b<\/h2>\n<p>\u307e\u305a\u3001<code>Factory<\/code>\u3092\u3064\u304f\u308a\u307e\u3057\u3087\u3046\u3002<br \/>\n<code>Factory<\/code>\u306f\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b\u30d1\u30c3\u30b1\u30fc\u30b8<code>Faker<\/code>\u3092\u3088\u308a\u4f7f\u3044\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306e\u3082\u306e\u3067\u3001\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3060\u3051\u3067\u6bce\u56de\u9055\u3046\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>factory(App\\User::class)-&gt;create();<\/strong><\/pre>\n<p>\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><strong>php artisan make:factory ProductFactory<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u4f5c\u6210\u3055\u308c\u305f<code>database\/factories\/ProductFactory.php<\/code>\u3092\u958b\u3044\u3066<code>$factory-&gt;define()<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre>$factory-&gt;define(Product::class, function (Faker $faker) {\r\n\r\n    <strong>$parameters = [<\/strong>\r\n<strong>        'category_id' =&gt; 2503,  \/\/ DIY\u3001\u5de5\u5177,<\/strong>\r\n<strong>        'hits' =&gt; 50            \/\/ 50\u4ef6\u53d6\u5f97<\/strong>\r\n<strong>    ];<\/strong>\r\n<strong>    return $faker-&gt;product($parameters);<\/strong>\r\n\r\n});<\/pre>\n<h2>Seeder\u3092\u3064\u304f\u308b<\/h2>\n<p>\u7d9a\u3044\u3066\u306f<code>Seeder<\/code>\u3067\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan make:seed ProductsTableSeeder<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001<code>database\/seeds\/ProductsTableSeeder.php<\/code>\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067<code>run()<\/code>\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre>public function run()\r\n{\r\n    <strong>for($i = 0 ; $i &lt; 25 ; $i++) {<\/strong>\r\n\r\n<strong>        factory(\\App\\Product::class)-&gt;create();<\/strong>\r\n\r\n<strong>    }<\/strong>\r\n}<\/pre>\n<p>\u5909\u66f4\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001<code>ProductsTableSeeder<\/code>\u3092<code>Laravel<\/code>\u306b\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002<code>database\/seeds\/DatabaseSeeder.php<\/code>\u3092\u958b\u3044\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8ffd\u52a0\u3057\u3066\u304a\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>&lt;?php\r\n\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass DatabaseSeeder extends Seeder\r\n{\r\n    \/**\r\n     * Seed the application's database.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function run()\r\n    {\r\n         \/\/$this-&gt;call(UsersTableSeeder::class);\r\n         <strong>$this-&gt;call(ProductsTableSeeder::class);<\/strong>\r\n    }\r\n}<\/pre>\n<p>\u3053\u308c\u3067\u4f5c\u696d\u306f\u5b8c\u4e86\u3067\u3059\uff01<\/p>\n<h1>\u5b9f\u969b\u306b\u30c6\u30b9\u30c8\u3057\u3066\u307f\u308b<\/h1>\n<p>\u3067\u306f\u3001\u3053\u3053\u307e\u3067\u3067\u4f5c\u6210\u3057\u305f<code>Factory<\/code>\u3068<code>Seeder<\/code>\u3092\u5b9f\u884c\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>php artisan migrate:fresh --seed<\/strong><\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4661\" style=\"border: 3px solid #000;\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_3.png\" alt=\"\" width=\"706\" height=\"493\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_3.png 706w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/09\/product_factory_3-300x209.png 300w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/p>\n<p>\u5b8c\u6210\u3067\u3059\uff01\ud83d\ude0a\u2728<\/p>\n<h1>\u3061\u306a\u307f\u306b<\/h1>\n<p>\u3061\u306a\u307f\u306b\u3001\u4eca\u56de\u7d39\u4ecb\u3057\u305fYahoo \u30b7\u30e7\u30c3\u30d4\u30f3\u30b0API\u306f2020\u5e746\u670830\u65e5\u3067\u7d42\u4e86\u3057\u3001\u65b0\u3057\u3044API\u304c2019\u5e7412\u6708\u306b\u767b\u5834\u3059\u308b\u305d\u3046\u3067\u3059\u306e\u3067\u3001\u3086\u304f\u3086\u304f\u306f\u30b3\u30fc\u30c9\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3067\u3066\u304f\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f<code>Faker<\/code>\u3092\u62e1\u5f35\u3057\u3066\u72ec\u81ea\u30d7\u30ed\u30d0\u30a4\u30c0\u30fc\u3092\u3064\u304f\u308a\u3001\u30c6\u30b9\u30c8\u306e\u5546\u54c1\u30c7\u30fc\u30bf\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u5b9f\u306f\u5f53\u521d\u306f\u4ed6\u306e\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u4f5c\u6210\u30b5\u30a4\u30c8\u304b\u3089\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u3053\u3068\u3082\u8003\u3048\u307e\u3057\u305f\u304c\u3001\u3044\u3064\u307e\u3067\u63d0\u4f9b\u3092\u7d9a\u3051\u308b\u304b\u304c\u672a\u77e5\u6570\u306a\u306e\u3067\u4eca\u56de\u306f<code>Yahoo API<\/code>\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002\uff08\u3068\u3044\u3063\u3066\u3082\u305d\u306eAPI\u3082\u30fb\u30fb\u30fb\u300c\u3061\u306a\u307f\u306b\u300d\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\ud83d\ude05\uff09<\/p>\n<p>\u305f\u3060\u3001\u4eca\u56de\u306e\u30c6\u30af\u30cb\u30c3\u30af\u3092\u4f7f\u3048\u3070\u72ec\u81ea\u306b\u597d\u304d\u306a\u30d0\u30f3\u30c9\u540d\u3084\u30bf\u30ec\u30f3\u30c8\u540d\u3001\u6f2b\u753b\u306a\u3069\u306e\u767b\u5834\u4eba\u7269\u306a\u3069\u3092\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3068\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u306e\u3067\u3001\u958b\u767a\u306e\u30e2\u30c1\u30d9\u30fc\u30b7\u30e7\u30f3\u3092\u5c11\u3057\u3060\u3051\u30a2\u30c3\u30d7\u3055\u305b\u3089\u308c\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u305c\u3072\u7686\u3055\u3093\u3082\u6d3b\u7528\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u306d\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\uff01<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3467 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9.png\" alt=\"\" width=\"216\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9.png 216w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9-203x300.png 203w\" sizes=\"auto, (max-width: 216px) 100vw, 216px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u3053\u308c\u306fLaravel\u306b\u9650\u3089\u305a\u3067\u3059\u304c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u3092\u69cb\u7bc9\u3059\u308b\u306b\u5f53\u305f\u3063\u3066\u591a\u304f\u306e\u5834\u5408\u3067\u3042\u308b\u3068\u4fbf\u5229\u3060\u306a\u3001\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002 \u305d\u308c\u304c\u3001\u300c\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u300d\u3067\u3059\u3002  &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=4656\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;\u3010Laravel\u3011Factory\u3067\u72ec\u81ea\u306b\u5546\u54c1\u306e\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":4663,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[176],"class_list":["post-4656","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","tag-176"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4656","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=4656"}],"version-history":[{"count":6,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4656\/revisions"}],"predecessor-version":[{"id":4666,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/4656\/revisions\/4666"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/4663"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}