Last active
June 27, 2024 17:53
-
-
Save abenevaut/7b8a33b546aea3520f9f19cbacd0315c to your computer and use it in GitHub Desktop.
This file contains 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 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