Created
January 13, 2022 13:28
-
-
Save dominiquevienne/d16476a7bcb24075543139306e3492d7 to your computer and use it in GitHub Desktop.
Seeding database with Blog Posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Database\Factories; | |
use Illuminate\Database\Eloquent\Factories\Factory; | |
class BlogPostFactory extends Factory | |
{ | |
/** | |
* Define the model's default state. | |
* | |
* @return array | |
*/ | |
public function definition() | |
{ | |
return [ | |
'title' => $this->faker->sentence, | |
'content' => $this->faker->text, | |
'author_name' => $this->faker->name, | |
]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Database\Seeders; | |
use App\Models\BlogPost; | |
use Illuminate\Database\Seeder; | |
class DatabaseSeeder extends Seeder | |
{ | |
/** | |
* Seed the application's database. | |
* | |
* @return void | |
*/ | |
public function run() | |
{ | |
// \App\Models\User::factory(10)->create(); | |
BlogPost::factory(20)->create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment