質問編集履歴
1
一部変更すると別のエラーが表示された
test
CHANGED
File without changes
|
test
CHANGED
@@ -71,16 +71,44 @@
|
|
71
71
|
];
|
72
72
|
}
|
73
73
|
```
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
74
|
### 補足情報(FW/ツールのバージョンなど)
|
82
75
|
|
83
76
|
laravel 9
|
84
77
|
mysql
|
85
78
|
phpunitは元々laravel9で入っていたものを使用
|
86
79
|
|
80
|
+
### 追記
|
81
|
+
|
82
|
+
下記サイトを参考にしデータベースを作成しましたが、テストを実行すると以下のエラーが表示されます。
|
83
|
+
参考サイト
|
84
|
+
https://qiita.com/miriwo/items/cf07098590fa23ad24f1
|
85
|
+
|
86
|
+
```
|
87
|
+
1) Tests\Feature\userTest::test_list_access
|
88
|
+
Illuminate\View\ViewException: Attempt to read property "role" on null (View: /Applications/MAMP/htdocs/ファイル名/resources/views/list.blade.php)
|
89
|
+
```
|
90
|
+
直訳すると「データベースの”role”がnullです」となりますが、一応マイグレーションファイルや「database/factories/UserFactory.php」には情報を記載しているのですが、どちらに記載すればエラーは解消されるでしょうか?
|
91
|
+
|
92
|
+
```テストでないマイグレーション
|
93
|
+
Schema::create('users', function (Blueprint $table) {
|
94
|
+
// $table->id();
|
95
|
+
$table->id();
|
96
|
+
$table->string('name', 10);
|
97
|
+
$table->string('email');
|
98
|
+
$table->string('password');
|
99
|
+
$table->string('img')->nullable();
|
100
|
+
$table->string('role')->default('11');
|
101
|
+
$table->timestamp('created_at')->useCurrent();
|
102
|
+
$table->timestamp('updated_at')->nullable();
|
103
|
+
});
|
104
|
+
```
|
105
|
+
```database/factories/UserFactory.php
|
106
|
+
return [
|
107
|
+
'name' => $this->faker->name(),
|
108
|
+
'email' => $this->faker->unique()->safeEmail(),
|
109
|
+
'password' => '$2y$10$rUBiykZ1QwGMPS.uctohCugP4Zv0SSlYXs2eDQ98xa5vc2prf3yOm',
|
110
|
+
'img' => 'images/***.jpg',
|
111
|
+
'role' => 11,
|
112
|
+
];
|
113
|
+
```
|
114
|
+
|