Skip to content

Instantly share code, notes, and snippets.

@abenevaut
Last active June 27, 2024 17:53
Show Gist options
  • Save abenevaut/7b8a33b546aea3520f9f19cbacd0315c to your computer and use it in GitHub Desktop.
Save abenevaut/7b8a33b546aea3520f9f19cbacd0315c to your computer and use it in GitHub Desktop.
<?php
namespace Database\Seeders;
use Database\Seeders\Domain\UserSeeder;
use Illuminate\Database\Seeder;
use Illuminate\Facade\DB;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
// Call a Factory
\App\Models\User::factory(10)->create();
// Mass insertion
DB::table('users')->insert([
[ 'email' => 'picard@example.com' ],
[ 'email' => 'janeway@example.com' ],
[ ... ],
]);
// Call a Seeder
$this->call(
UserSeeder::class,
$silent = false,
[ /* arguments / context for the seeder */ ]
);
// Call instruction from a package, example with `spatie/laravel-permission`
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment