Laravel factory changed in Laravel 8

avatar
Feb 21, 2023 ยท Snippet ยท 1 min, 100 words

In Laravel 8 there are some changes in factory. Let's see that ๐Ÿ‘‡

PostsTableSeeder.php

factory(App\Models\Post::class, 30)->create();

// to ๐Ÿ‘‡

\App\Models\Post::factory()->count(30)->create();

PostFactory.php

protected $model = App\Models\Post::class;
// to ๐Ÿ‘‡
protected $model = \App\Models\Post::class;

------------------------------------------

// and you have to change

'title' => $faker->text(50),
           'body' => $faker->text(200)
// to ๐Ÿ‘‡
'title' => $this->faker->text(50),
        'body' => $this->faker->text(200)

Comments

No comments yetโ€ฆ