Berkarar/modules/backend/database/seeds/SeedSetupAdmin.php

63 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2022-08-28 19:50:26 +00:00
<?php namespace Backend\Database\Seeds;
use Seeder;
use Backend\Models\User;
use Backend\Models\UserRole;
use Backend\Models\UserGroup;
class SeedSetupAdmin extends Seeder
{
public static $email = 'admin@domain.tld';
public static $login = 'admin';
public static $password = 'admin';
public static $firstName = 'Admin';
public static $lastName = 'Person';
public function setDefaults($values)
{
if (!is_array($values)) {
return;
}
foreach ($values as $attribute => $value) {
static::$$attribute = $value;
}
}
public function run()
{
2023-07-14 08:02:08 +00:00
UserRole::create([
'name' => 'Publisher',
'code' => UserRole::CODE_PUBLISHER,
'description' => 'Site editor with access to publishing tools.',
]);
$role = UserRole::create([
'name' => 'Developer',
'code' => UserRole::CODE_DEVELOPER,
'description' => 'Site administrator with access to developer tools.',
]);
$group = UserGroup::create([
'name' => 'Owners',
'code' => UserGroup::CODE_OWNERS,
'description' => 'Default group for website owners.',
'is_new_user_default' => false
]);
2022-08-28 19:50:26 +00:00
$user = User::create([
'email' => static::$email,
'login' => static::$login,
'password' => static::$password,
'password_confirmation' => static::$password,
'first_name' => static::$firstName,
'last_name' => static::$lastName,
'permissions' => [],
'is_superuser' => true,
'is_activated' => true,
2023-07-14 08:02:08 +00:00
'role_id' => $role->id
2022-08-28 19:50:26 +00:00
]);
2023-07-14 08:02:08 +00:00
$user->addGroup($group);
2022-08-28 19:50:26 +00:00
}
}