{"id":10694,"date":"2020-05-17T09:33:18","date_gmt":"2020-05-17T00:33:18","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=10694"},"modified":"2023-05-27T21:15:57","modified_gmt":"2023-05-27T12:15:57","slug":"%e3%80%90laravel%e3%80%91%e3%82%b7%e3%83%bc%e3%83%80%e3%83%bc%ef%bc%88%e3%83%86%e3%82%b9%e3%83%88%e3%83%87%e3%83%bc%e3%82%bf%e3%81%ae%e4%bd%9c%e6%88%90%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=10694","title":{"rendered":"\u3010Laravel\u3011\u30b7\u30fc\u30c0\u30fc\uff08\u30c6\u30b9\u30c8\u30c7\u30fc\u30bf\u306e\u4f5c\u6210\uff09"},"content":{"rendered":"<h2>\u30b7\u30fc\u30c0\u30fc\u306e\u4f5c\u6210<\/h2>\n<pre class=\"lang:default decode:true \">php artisan make:seeder \u30b7\u30fc\u30c0\u30fc\u540d<\/pre>\n<p>\u4e0b\u8a18\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30b7\u30fc\u30c0\u30fc\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">database\/seeds\/\u30b7\u30fc\u30c0\u30fc\u540d.php<\/pre>\n<h2>\u30c7\u30fc\u30bf\u306e\u66f8\u304d\u65b9<\/h2>\n<h3>\u4f5c\u6210\u3057\u305f\u30b7\u30fc\u30c0\u30fc\u306e\u7de8\u96c6<\/h3>\n<p>\u5148\u307b\u3069\u4f5c\u6210\u3057\u305f<span style=\"color: #ff0000;\"><strong>\u30b7\u30fc\u30c0\u30fc\uff08\u4f8b\u3067\u8a00\u3048\u3070UsersTableSeeder\uff09<\/strong><\/span>\u3092\u4e0b\u8a18\u306e\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n\r\nuse Illuminate\\Database\\Seeder;\r\n\r\nclass UsersTableSeeder extends Seeder\r\n{\r\n    \/**\r\n     * Run the database seeds.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function run()\r\n    {\r\n        DB::table('users')-&gt;insert([\r\n            [\r\n            'name' =&gt; '\u3042\u3042\u3042',\r\n            'email' =&gt; 'test5@test.com',\r\n            'password' =&gt; Hash::make('password123'),\r\n            ],\r\n            [\r\n            'name' =&gt; '\u3044\u3044\u3044',\r\n            'email' =&gt; 'test6@test.com',\r\n            'password' =&gt; Hash::make('password123'),\r\n            ]\r\n        ]);\r\n    }\r\n}\r\n<\/pre>\n<h3>DatabaseSeeder.php\u3092\u7de8\u96c6\u3059\u308b\u3002<\/h3>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306b\u4f5c\u6210\u3057\u305f\u30b7\u30fc\u30c0\u30fc\u3092\u8aad\u307f\u8fbc\u3080\u3088\u3046\u306b\u7de8\u96c6\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">&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    }\r\n}<\/pre>\n<h3>composer\u306e\u30aa\u30fc\u30c8\u30ed\u30fc\u30c0\u30fc\u3092\u518d\u4f5c\u6210\u3059\u308b\u3002<\/h3>\n<pre class=\"lang:default decode:true\">composer dump-autoload<\/pre>\n<h3>\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b\u3002<\/h3>\n<pre class=\"lang:default decode:true \">php artisan db:seed<\/pre>\n<h2>\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b\u306b\u306f\uff1f<\/h2>\n<p>seeder\u306b\u52a0\u3048\u3066\u4e0b\u8a18\u306e\u4ed5\u7d44\u307f\u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>factory<\/li>\n<li>faker<\/li>\n<\/ul>\n<h3>factory<\/h3>\n<p>faker\u3067\u30c7\u30fc\u30bf\u3092\u8a18\u8ff0\u3059\u308b\u96db\u5f62\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h3>faker<\/h3>\n<p>\u4efb\u610f\u306e\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u3092\u4f5c\u6210\u3059\u308b\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u30d5\u30a1\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/h3>\n<pre class=\"lang:default decode:true \">php artisan make:factory \u30d5\u30a1\u30af\u30c8\u30ea\u540d<\/pre>\n<p>\u4e0b\u8a18\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">database\/factories\/\u30d5\u30a1\u30af\u30c8\u30ea\u540d.php<\/pre>\n<p>\u4e0b\u8a18\u3092\u66f8\u304d\u63db\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php\r\n\r\n\/** @var \\Illuminate\\Database\\Eloquent\\Factory $factory *\/\r\n\r\nuse App\\\u2605Model;\u3000\u2190Model\u3092\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b\u5bfe\u8c61\u306e\u30e2\u30c7\u30eb\u306b\u66f8\u304d\u63db\u3048\u308b\u3002\r\nuse Faker\\Generator as Faker;\r\n\r\n$factory-&gt;define(\u2605Model::class, function (Faker $faker) {\u3000\u2190Model\u3092\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b\u5bfe\u8c61\u306e\u30e2\u30c7\u30eb\u306b\u66f8\u304d\u63db\u3048\u308b\u3002\r\n    return [\r\n        \/\/\r\n    ];\r\n});<\/pre>\n<h3>faker\u3092\u65e5\u672c\u8a9e\u5316\u3059\u308b<\/h3>\n<pre class=\"lang:default decode:true \">'faker_locale' =&gt; 'en_US',<\/pre>\n<p>\u2193\u4e0b\u8a18\u306e\u3088\u3046\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">'faker_locale' =&gt; 'ja_JP',<\/pre>\n<h3>faker\u306e\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3059\u308b\u3002<\/h3>\n<p>\u4e0b\u8a18\u306e\u3088\u3046\u306afaker\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u9805\u76ee\u3084\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30c7\u30fc\u30bf\u3092\u6e96\u5099\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">$factory-&gt;define(ContactForm::class, function (Faker $faker) {\r\n    return [\r\n        '\u30d5\u30a3\u30fc\u30eb\u30c91' =&gt; $faker-&gt;name,\r\n        '\u30d5\u30a3\u30fc\u30eb\u30c92' =&gt; $faker-&gt;realText(50),\r\n    ];\r\n});<\/pre>\n<h4>faker\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u30e1\u30bd\u30c3\u30c9<\/h4>\n<table>\n<tbody>\n<tr>\n<th>\u30e1\u30bd\u30c3\u30c9\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>realText(\u6587\u5b57\u6570)<\/td>\n<td>\u4efb\u610f\u306e\u65e5\u672c\u8a9e\u6587\u5b57\u5217\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>unique()<\/td>\n<td>\u4e00\u610f\u306e\u30c7\u30fc\u30bf\u306b\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>randomElement<\/td>\n<td>\u4efb\u610f\u306e\u5024\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>numberBetween<\/td>\n<td>\u4efb\u610f\u306e\u9593\u306b\u3042\u308b\u6570\u5b57\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>faker\u3067\u7528\u610f\u3055\u308c\u3066\u3044\u308b\u9805\u76ee<\/h4>\n<table>\n<tbody>\n<tr>\n<th>\u9805\u76ee\u540d<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>name<\/td>\n<td>\u4efb\u610f\u306e\u540d\u524d\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>email<\/td>\n<td>\u4efb\u610f\u306eemail\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>url<\/td>\n<td>\u4efb\u610f\u306eurl\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u30b7\u30fc\u30c0\u30fc\u3092\u4f5c\u6210\u3057\u3066\u30d5\u30a1\u30af\u30c8\u30ea\u3092\u547c\u3073\u8fbc\u307f\u307e\u3059\u3002<\/h3>\n<p>\u30c7\u30fc\u30bf\u4ef6\u6570\u306b\u4f8b\u3048\u307010\u3068\u6307\u5b9a\u3059\u308c\u307010\u4ef6\u306e\u30c0\u30df\u30fc\u30c7\u30fc\u30bf\u3092\u751f\u6210\u3059\u308b\u4e8b\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">&lt;?php\r\n\r\nuse Illuminate\\Database\\Seeder;\r\nuse App\\Models\\\u30e2\u30c7\u30eb\u540d;\r\n\r\nclass ContactFormSeeder extends Seeder\r\n{\r\n    \/**\r\n     * Run the database seeds.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function run()\r\n    {\r\n        factory(\u30e2\u30c7\u30eb\u540d::class,\u30c7\u30fc\u30bf\u4ef6\u6570)-&gt;create();\r\n    }\r\n}\r\n<\/pre>\n<h3>DatabaseSeeder\u306b\u8ffd\u52a0\u3059\u308b\u3002<\/h3>\n<pre class=\"lang:default decode:true  \">&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        $this-&gt;call(\u4efb\u610f\u306e\u30b7\u30fc\u30c0\u30fc::class);\u3000\u2605\u8ffd\u52a0\u3059\u308b\u3002\r\n    }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"\u30b7\u30fc\u30c0\u30fc\u306e\u4f5c\u6210 php artisan make:seeder \u30b7\u30fc\u30c0\u30fc\u540d \u4e0b\u8a18\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30b7\u30fc\u30c0\u30fc\u306e\u30d5\u30a1\u30a4\u30eb\u304c\u751f\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002 database\/seeds\/\u30b7\u30fc\u30c0\u30fc\u540d.php \u30c7\u30fc\u30bf\u306e\u66f8\u304d\u65b9 \u4f5c\u6210\u3057\u305f\u30b7\u30fc\u30c0\u30fc\u306e [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[99],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10694"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10694"}],"version-history":[{"count":10,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10694\/revisions"}],"predecessor-version":[{"id":20326,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/10694\/revisions\/20326"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10694"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}