Ekapp/skolehjem/database/seeds/RoleSeeder.php

49 lines
1.7 KiB
PHP

<?php
use Illuminate\Database\Seeder;
class RoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$roles = [
"Administrator" => "Administrator",
"Bruger" => "Bruger",
];
foreach ($roles as $key => $value) {
try {
if (\Spatie\Permission\Models\Role::findByName($key))
continue;
} catch (Exception $e) {
$role = new \Spatie\Permission\Models\Role();
$role->name = $key;
$role->description = $value;
$role->save();
}
}
//Give all permissions to Administrator (id: 1)
foreach (\Spatie\Permission\Models\Permission::all() as $permission) {
\Spatie\Permission\Models\Role::query()->find(1)->get()[0]->givePermissionTo($permission);
}
//Give permissions to Bruger (id: 2)
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("event.list");
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("link.external.list");
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("contact.list");
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("feedback.create");
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("menuplan.list");
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("washing.machine.reservation.create");
\Spatie\Permission\Models\Role::query()->find(2)->get()[0]->givePermissionTo("washing.machine.reservation.delete");
}
}