You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
49 lines
1.5 KiB
<?php
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class InitAdminSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public $guardName = "admin";
|
|
|
|
public function run()
|
|
{
|
|
$this->initPermissions();
|
|
$this->initRole();
|
|
$this->initAdmin();
|
|
$permissions = \Spatie\Permission\Models\Permission::orderBy("id", "desc")->limit(3)->get();
|
|
$role = \Spatie\Permission\Models\Role::orderBy("id", "desc")->first();
|
|
$admin = \App\Admin::orderBy("id", "desc")->first();
|
|
$role->syncPermissions($permissions);
|
|
$admin->syncRoles($role);
|
|
}
|
|
|
|
public function initPermissions()
|
|
{
|
|
\Spatie\Permission\Models\Permission::create(["guard_name" => $this->guardName, "name" => "权限菜单", "url" => "admin/permission"]);
|
|
\Spatie\Permission\Models\Permission::create(["guard_name" => $this->guardName, "name" => "角色管理", "url" => "admin/role"]);
|
|
\Spatie\Permission\Models\Permission::create(["guard_name" => $this->guardName, "name" => "用户管理", "url" => "admin/admin"]);
|
|
}
|
|
|
|
public function initRole()
|
|
{
|
|
\Spatie\Permission\Models\Role::create([
|
|
"guard_name" => $this->guardName,
|
|
"name" => "系统管理员"
|
|
]);
|
|
}
|
|
|
|
public function initAdmin()
|
|
{
|
|
\App\Admin::insert([
|
|
["username" => "admin", "name" => "系统管理员", "password" => \Illuminate\Support\Facades\Hash::make("Admin" . date("Y"))]
|
|
]);
|
|
}
|
|
}
|