Reputation: 21
I'm trying to seed my roles table for different roles in this company but when I run "php artisan migrate:fresh --seed" I get no error messages but there is no data in my database.
<?php
use App\Role;
use Illuminate\Database\Seeder;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$roles = [
[
'name' => 'Admin',
],
[
'name' => 'Klant',
]
];
foreach ($roles as $role){
Role::insert([
'name' => $role['name'],
'created_at' => now(),
'updated_at' => now()
]);
}
}
}
Upvotes: 1
Views: 615
Reputation: 5358
You have to add any custom seeders to the database/seeders/DatabaseSeeder.php
file as this is the file that gets called per default when you're seeding the database.
class DatabaseSeeder
{
public function run()
{
$this->call([
RoleSeeder::class,
]);
}
}
Upvotes: 3