質問編集履歴

1

codeのミス修正

2021/12/25 00:29

投稿

ryo_1
ryo_1

スコア3

test CHANGED
File without changes
test CHANGED
@@ -74,6 +74,46 @@
74
74
 
75
75
 
76
76
 
77
+ class BlogsTableSeeder extends Seeder
78
+
79
+ {
80
+
81
+ /**
82
+
83
+ * Seed the application's database.
84
+
85
+ *
86
+
87
+ * @return void
88
+
89
+ */
90
+
91
+ public function run()
92
+
93
+ {
94
+
95
+ // $this->call(UsersTableSeeder::class);
96
+
97
+ \App\Models\Blog::factory()->count(10)->create();
98
+
99
+ }
100
+
101
+ }
102
+
103
+ ```
104
+
105
+ DatebaseSeeder.php
106
+
107
+ ```ここに言語を入力
108
+
109
+ <?php
110
+
111
+
112
+
113
+ use Illuminate\Database\Seeder;
114
+
115
+
116
+
77
117
  class DatabaseSeeder extends Seeder
78
118
 
79
119
  {
@@ -94,15 +134,15 @@
94
134
 
95
135
  // $this->call(UsersTableSeeder::class);
96
136
 
97
- \App\Models\Blog::factory()->count(10)->create();
137
+ $this->call(BlogsTableSeeder::class);
98
138
 
99
139
  }
100
140
 
101
- }
141
+ }
102
-
142
+
103
- ```
143
+ ```
104
-
144
+
105
- DatebaseSeeder.php
145
+ BlogsFactory.php
106
146
 
107
147
  ```ここに言語を入力
108
148
 
@@ -110,31 +150,45 @@
110
150
 
111
151
 
112
152
 
153
+ namespace Database\Factories;
154
+
155
+
156
+
157
+ use App\Models\Blog;
158
+
113
- use Illuminate\Database\Seeder;
159
+ use Illuminate\Database\Eloquent\Factories\Factory;
114
-
115
-
116
-
160
+
161
+
162
+
117
- class DatabaseSeeder extends Seeder
163
+ class BlogsFactory extends Factory
118
-
164
+
119
- {
165
+ {
166
+
167
+
168
+
169
+ protected $model = \App\Models\Blog::class;
120
170
 
121
171
  /**
122
172
 
123
- * Seed the application's database.
173
+ * Define the model's default state.
124
174
 
125
175
  *
126
176
 
127
- * @return void
177
+ * @return array
128
178
 
129
179
  */
130
180
 
131
- public function run()
181
+ public function definition()
132
182
 
133
183
  {
134
184
 
185
+ return [
186
+
187
+ 'title' => $this->faker->word,
188
+
135
- // $this->call(UsersTableSeeder::class);
189
+ 'content' => $this->faker->realText
136
-
190
+
137
- $this->call(BlogsTableSeeder::class);
191
+ ];
138
192
 
139
193
  }
140
194
 
@@ -142,7 +196,7 @@
142
196
 
143
197
  ```
144
198
 
145
- BlogsFactory.php
199
+ app\Models\Blog.php
146
200
 
147
201
  ```ここに言語を入力
148
202
 
@@ -150,98 +204,44 @@
150
204
 
151
205
 
152
206
 
153
- namespace Database\Factories;
154
-
155
-
156
-
157
- use App\Models\Blog;
207
+ namespace App\Models;
208
+
209
+
210
+
211
+
212
+
158
-
213
+ use Illuminate\Database\Eloquent\Model;
214
+
159
- use Illuminate\Database\Eloquent\Factories\Factory;
215
+ use Illuminate\Database\Eloquent\BlogsFactory;
160
-
161
-
162
-
216
+
217
+
218
+
163
- class BlogsFactory extends Factory
219
+ class Blog extends Model
164
-
220
+
165
- {
221
+ {
222
+
166
-
223
+ // テーブル名
167
-
168
-
224
+
169
- protected $model = \App\Models\Blog::class;
225
+ protected $table = 'blogs';
170
-
226
+
227
+
228
+
171
- /**
229
+ // 可変項目
172
-
173
- * Define the model's default state.
230
+
174
-
175
- *
176
-
177
- * @return array
178
-
179
- */
180
-
181
- public function definition()
231
+ protected $fillable =
182
-
232
+
183
- {
233
+ [
184
-
185
- return [
234
+
186
-
187
- 'title' => $this->faker->word,
235
+ 'title',
188
-
236
+
189
- 'content' => $this->faker->realText
237
+ 'content'
190
-
238
+
191
- ];
239
+ ];
192
-
193
- }
194
240
 
195
241
  }
196
242
 
197
243
  ```
198
244
 
199
- app\Models\Blog.php
200
-
201
- ```ここに言語を入力
202
-
203
- <?php
204
-
205
-
206
-
207
- namespace App\Models;
208
-
209
-
210
-
211
-
212
-
213
- use Illuminate\Database\Eloquent\Model;
214
-
215
- use Illuminate\Database\Eloquent\BlogsFactory;
216
-
217
-
218
-
219
- class Blog extends Model
220
-
221
- {
222
-
223
- // テーブル名
224
-
225
- protected $table = 'blogs';
226
-
227
-
228
-
229
- // 可変項目
230
-
231
- protected $fillable =
232
-
233
- [
234
-
235
- 'title',
236
-
237
- 'content'
238
-
239
- ];
240
-
241
- }
242
-
243
- ```
244
-
245
245
  ### 試したこと
246
246
 
247
247
  composer dump-autoloadを打つ。