database/seeders/DatabaseSeeder.php
/**
     * Seed the application's database.
     *
     * @return void
     */
Seed the application's database.
@return void
Seed the application ' s database . @return void
public function run()
    {
        User::truncate();
        Category::truncate();
        Post::truncate();
        $johnWick = User::factory()->create([
            'name' => 'John Wick',
            'username' => 'johnwick',
        ]);
        Post::factory(5)->create([
            'user_id' => $johnWick->id,
        ]);
        $loki = User::factory()->create([
            'name' => 'Loki',
            'username' => 'loki',
        ]);
        Post::factory(5)->create([
            'user_id' => $loki->id,
        ]);
    }
public function run ( ) { User :: truncate ( ) ; Category :: truncate ( ) ; Post :: truncate ( ) ; $ johnWick = User :: factory ( ) -> create ( [ 'name' => 'John Wick' , 'username' => 'johnwick' , ] ) ; Post :: factory ( 5 ) -> create ( [ 'user_id' => $ johnWick -> id , ] ) ; $ loki = User :: factory ( ) -> create ( [ 'name' => 'Loki' , 'username' => 'loki' , ] ) ; Post :: factory ( 5 ) -> create ( [ 'user_id' => $ loki -> id , ] ) ; }
Seed the application's database.
Seed the application ' s database .
// Truncate users, categories and posts data. // Create a user. // Create posts for the above user. // Create a user. // Create posts for the above user.