2020-07-28 08:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
2020-07-30 12:38:32 +00:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2020-07-28 08:22:45 +00:00
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class RoleSeeder extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$roles = [
|
2020-07-29 11:28:25 +00:00
|
|
|
"Administrator" => "Administrator",
|
2020-07-30 10:28:05 +00:00
|
|
|
"Bruger" => "Bruger",
|
2020-07-28 08:22:45 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($roles as $key => $value) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (\Spatie\Permission\Models\Role::findByName($key))
|
|
|
|
continue;
|
|
|
|
} catch (Exception $e) {
|
2020-07-30 10:28:05 +00:00
|
|
|
$role = new \Spatie\Permission\Models\Role();
|
2020-07-28 08:22:45 +00:00
|
|
|
|
2020-07-30 10:28:05 +00:00
|
|
|
$role->name = $key;
|
|
|
|
$role->description = $value;
|
2020-07-28 08:22:45 +00:00
|
|
|
|
2020-07-30 10:28:05 +00:00
|
|
|
$role->save();
|
2020-07-28 08:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-30 10:28:05 +00:00
|
|
|
|
|
|
|
//Give all permissions to Administrator (id: 1)
|
|
|
|
foreach (\Spatie\Permission\Models\Permission::all() as $permission) {
|
2020-07-30 12:38:32 +00:00
|
|
|
\Spatie\Permission\Models\Role::query()->find(1)->first()->givePermissionTo($permission);
|
2020-07-30 10:28:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 12:38:32 +00:00
|
|
|
//Bruger Permissions
|
|
|
|
$brugerPermissions = new Collection();
|
|
|
|
|
2020-08-31 07:36:10 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "contact.show")->first());
|
2020-07-30 12:38:32 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "feedback.create")->first());
|
2020-08-31 07:36:10 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "menuplan.show")->first());
|
2020-07-30 12:38:32 +00:00
|
|
|
$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());
|
2020-08-31 07:36:10 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "washing.machine.reservation.show")->first());
|
2020-08-31 06:16:26 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "event.show")->first());
|
2020-09-02 09:40:36 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "userevent.create")->first());
|
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "userevent.delete")->first());
|
2020-08-31 06:16:26 +00:00
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "guides.show")->first());
|
|
|
|
$brugerPermissions->add(\Spatie\Permission\Models\Permission::query()->where("name", "=", "news.show")->first());
|
2020-07-30 12:38:32 +00:00
|
|
|
|
2020-07-30 10:28:05 +00:00
|
|
|
//Give permissions to Bruger (id: 2)
|
2020-07-30 12:38:32 +00:00
|
|
|
foreach ($brugerPermissions as $permission) {
|
|
|
|
\Spatie\Permission\Models\Role::query()->find(2)->givePermissionTo($permission);
|
|
|
|
}
|
2020-07-28 08:22:45 +00:00
|
|
|
}
|
|
|
|
}
|