質問編集履歴
1
周辺ファイル追記しました。
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
docker + laravel で
|
1
|
+
docker + laravel で seed をしたい。
|
body
CHANGED
@@ -5,4 +5,91 @@
|
|
5
5
|
```
|
6
6
|
調べると名前空間のマッピングが必要らしく```composer dump-autoload```を実行する必要があるらしいです。
|
7
7
|
しかし、dockerでの開発のため、どのように実行したらいいか正確なコードが得られませんでした。
|
8
|
-
どのようにしたらいいか、正解を知っている方がいましたら教えてください。
|
8
|
+
どのようにしたらいいか、正解を知っている方がいましたら教えてください。
|
9
|
+
|
10
|
+
下記周辺ファイルを追記しておきます。
|
11
|
+
|
12
|
+
```DatabaseSeeder
|
13
|
+
<?php
|
14
|
+
|
15
|
+
use Illuminate\Database\Seeder;
|
16
|
+
|
17
|
+
class DatabaseSeeder extends Seeder
|
18
|
+
{
|
19
|
+
/**
|
20
|
+
* Seed the application's database.
|
21
|
+
*
|
22
|
+
* @return void
|
23
|
+
*/
|
24
|
+
public function run()
|
25
|
+
{
|
26
|
+
$this->call(UsersTableSeeder::class);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
```UsersTableSeeder
|
33
|
+
<?php
|
34
|
+
|
35
|
+
use Illuminate\Database\Seeder;
|
36
|
+
|
37
|
+
class UsersTableSeeder extends Seeder
|
38
|
+
{
|
39
|
+
/**
|
40
|
+
* Run the database seeds.
|
41
|
+
*
|
42
|
+
* @return void
|
43
|
+
*/
|
44
|
+
public function run()
|
45
|
+
{
|
46
|
+
$param =[
|
47
|
+
'name' => 'name',
|
48
|
+
'email' => 'fugafuga@example.com',
|
49
|
+
'password' => 'hogehoge',
|
50
|
+
];
|
51
|
+
DB::table('users')->insert($param);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
```CreateUsersTable
|
58
|
+
<?php
|
59
|
+
|
60
|
+
use Illuminate\Support\Facades\Schema;
|
61
|
+
use Illuminate\Database\Schema\Blueprint;
|
62
|
+
use Illuminate\Database\Migrations\Migration;
|
63
|
+
|
64
|
+
class CreateUsersTable extends Migration
|
65
|
+
{
|
66
|
+
/**
|
67
|
+
* Run the migrations.
|
68
|
+
*
|
69
|
+
* @return void
|
70
|
+
*/
|
71
|
+
public function up()
|
72
|
+
{
|
73
|
+
Schema::create('users', function (Blueprint $table) {
|
74
|
+
$table->increments('id');
|
75
|
+
$table->string('name');
|
76
|
+
$table->string('email')->unique();
|
77
|
+
$table->timestamp('email_verified_at')->nullable();
|
78
|
+
$table->string('password');
|
79
|
+
$table->rememberToken();
|
80
|
+
$table->timestamps();
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Reverse the migrations.
|
86
|
+
*
|
87
|
+
* @return void
|
88
|
+
*/
|
89
|
+
public function down()
|
90
|
+
{
|
91
|
+
Schema::dropIfExists('users');
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
```
|