61 lines
2.7 KiB
PHP
61 lines
2.7 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
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)->first()->givePermissionTo($permission);
|
|
}
|
|
|
|
//Bruger Permissions
|
|
$brugerPermissions = new Collection();
|
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "contact.show")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "feedback.create")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "menuplan.show")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.create")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.delete")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.show")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "event.show")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "userevent.create")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "userevent.delete")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "guides.show")->first());
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "news.show")->first());
|
|
|
|
//Give permissions to Bruger (id: 2)
|
|
foreach ($brugerPermissions as $permission) {
|
|
\Spatie\Permission\Models\Role::query()->find(2)->givePermissionTo($permission);
|
|
}
|
|
}
|
|
}
|