Skip to content

Instantly share code, notes, and snippets.

@dominiquevienne
Created January 13, 2022 13:28
Show Gist options
  • Save dominiquevienne/d16476a7bcb24075543139306e3492d7 to your computer and use it in GitHub Desktop.
Save dominiquevienne/d16476a7bcb24075543139306e3492d7 to your computer and use it in GitHub Desktop.
Seeding database with Blog Posts
<?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,
];
}
}
<?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