Laravel Basic
Laravel Form
Laravel Database
Laravel Advance
A Seeder in Laravel is used to populate your database with test or default data.
👉 Example:
Seeders help you develop and test without manually entering data.
✅ Quickly fill database with dummy data.
✅ Keep initial data consistent across environments (local, staging, production).
✅ No need to manually insert records via SQL.
✅ Great for testing with sample datasets.
Use Artisan command:
php artisan make:seeder UserSeeder
This creates a file:database/seeders/UserSeeder.php
Example UserSeeder:
namespace Database\Seeders; use Illuminate\Database\Seeder; use App\Models\User; class UserSeeder extends Seeder { public function run(): void { User::create([ 'name' => 'Admin User', 'email' => 'admin@example.com', 'password' => bcrypt('password'), ]); // Create multiple users User::factory()->count(10)->create(); } }
php artisan db:seed --class=UserSeeder
Laravel uses DatabaseSeeder.php
as the main entry point.
Path: database/seeders/DatabaseSeeder.php
You can call multiple seeders inside:
namespace Database\Seeders; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { public function run(): void { $this->call([ UserSeeder::class ]); } }
php artisan db:seed
Refresh the database and run seeders:
php artisan migrate:fresh --seed
Or with specific seeder:
php artisan migrate:fresh --seeder=UserSeeder