Запускаю seederы и мне выдает ошибку. Фабрики запускаются в таком порядке: User->Category->Post->Comment
ErrorException
Undefined offset: 1
at vendor/laravel/framework/src/Illuminate/Collections/Collection.php:1623
1619▕ */
1620▕ #[\ReturnTypeWillChange]
1621▕ public function offsetGet($key)
1622▕ {
➜ 1623▕ return $this->items[$key];
1624▕ }
1625▕
1626▕ /**
1627▕ * Set the item at a given offset.
+1 vendor frames
2 database/factories/PostFactory.php:16
Illuminate\Support\Collection::offsetGet()
+6 vendor frames
9 [internal]:0
Illuminate\Database\Eloquent\Factories\Factory::Illuminate\Database\Eloquent\Factories\{closure}()
CategoryFactory.php
return [
'name' => $this->faker->realText(rand(20,30)),
'slug' => $this->faker->password(),
'image' => null,
'posts' => Post::pluck('id')[$this->faker->numberBetween(1, Post::count())],
];
PostFactory.php
return [
return [
'user_id' => User::pluck('id')[$this->faker->numberBetween(1, User::count())],
'category_id' => Category::pluck('id')[$this->faker->numberBetween(1, Category::count())],
'title' => $this->faker->realText(rand(25, 30)),
'slug' => $this->faker->password() ,
'image' => null ,
'content' => $this->faker->realText(rand(200, 300)),
'published_by' => true ,
'created_at' => $this->faker->dateTimeBetween('-60 days', '-30 days'),
'updated_at' => $this->faker->dateTimeBetween('-20 days', '-1 days'),
];
];
CommentFactory.php
return [
'post_id' => Post::pluck('id')[$this->faker->numberBetween(1, Post::count())],
'user_id' => User::pluck('id')[$this->faker->numberBetween(1, User::count())],
'published_by' => true,
'content' => $this->faker->paragraph(),
];