192 lines
4.9 KiB
PHP
192 lines
4.9 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class RolesAndPermissions extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
// Reset cached roles and permissions
|
|
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
|
|
|
$permissions = [
|
|
// Khách hàng
|
|
'customer.view',
|
|
'customer.create',
|
|
'customer.edit',
|
|
'customer.destroy',
|
|
'customer.manager',
|
|
|
|
// Chiến dịch email
|
|
'mail-campaign.view',
|
|
'mail-campaign.create',
|
|
'mail-campaign.manager',
|
|
|
|
// Khách tiềm năng
|
|
'lead.view',
|
|
'lead.create',
|
|
'lead.edit',
|
|
'lead.destroy',
|
|
'lead.manager',
|
|
|
|
// Nhân sự
|
|
'administrator.view',
|
|
'administrator.create',
|
|
'administrator.edit',
|
|
'administrator.destroy',
|
|
'administrator.manager',
|
|
|
|
// Sản phẩm / Dịch vụ
|
|
'product-service.view',
|
|
'product-service.create',
|
|
'product-service.edit',
|
|
'product-service.destroy',
|
|
'product-service.manager',
|
|
|
|
// Đơn hàng
|
|
'order.view',
|
|
'order.create',
|
|
'order.edit',
|
|
'order.destroy',
|
|
'order.manager',
|
|
|
|
// Hóa đơn
|
|
'invoice.view',
|
|
'invoice.create',
|
|
'invoice.edit',
|
|
'invoice.destroy',
|
|
'invoice.manager',
|
|
|
|
// Mã giảm giá
|
|
'coupon.view',
|
|
'coupon.create',
|
|
'coupon.edit',
|
|
'coupon.destroy',
|
|
'coupon.manager',
|
|
|
|
// Bài viết
|
|
'post.view',
|
|
'post.create',
|
|
'post.edit',
|
|
'post.destroy',
|
|
'post.manager',
|
|
|
|
// Hỗ trợ
|
|
'support.view',
|
|
'support.create',
|
|
'support.edit',
|
|
'support.destroy',
|
|
'support.manager',
|
|
|
|
// Thanh toán
|
|
'payment.view',
|
|
'payment.create',
|
|
'payment.edit',
|
|
'payment.destroy',
|
|
'payment.manager',
|
|
|
|
// Module DNS
|
|
'module-dns.view',
|
|
'module-dns.create',
|
|
'module-dns.edit',
|
|
'module-dns.destroy',
|
|
'module-dns.manager',
|
|
|
|
// Module Hosting
|
|
'module-hosting.view',
|
|
'module-hosting.create',
|
|
'module-hosting.edit',
|
|
'module-hosting.destroy',
|
|
'module-hosting.manager',
|
|
|
|
// Module vCenter
|
|
'module-vcenter.view',
|
|
'module-vcenter.create',
|
|
'module-vcenter.edit',
|
|
'module-vcenter.destroy',
|
|
'module-vcenter.manager',
|
|
|
|
// IP Pool
|
|
'module-ippool.view',
|
|
'module-ippool.create',
|
|
'module-ippool.edit',
|
|
'module-ippool.destroy',
|
|
'module-ippool.manager',
|
|
|
|
// Gói dịch vụ
|
|
'package-module.view',
|
|
'package-module.create',
|
|
'package-module.edit',
|
|
'package-module.destroy',
|
|
'package-module.manager',
|
|
|
|
// Menu
|
|
'menu.view',
|
|
'menu.create',
|
|
'menu.edit',
|
|
'menu.destroy',
|
|
'menu.manager',
|
|
|
|
// Email Template
|
|
'email-template.view',
|
|
'email-template.create',
|
|
'email-template.edit',
|
|
'email-template.destroy',
|
|
'email-template.manager',
|
|
|
|
// Cài đặt
|
|
'setting.manager',
|
|
'smtp.manager',
|
|
'auto-banking.manager',
|
|
'system-log.manager',
|
|
|
|
// Tên miền
|
|
'domain.view',
|
|
'domain.create',
|
|
'domain.edit',
|
|
'domain.destroy',
|
|
'domain.manager',
|
|
|
|
// Hosting
|
|
'hosting.view',
|
|
'hosting.create',
|
|
'hosting.edit',
|
|
'hosting.destroy',
|
|
|
|
// Vai trò & Phân quyền
|
|
'role.view',
|
|
'role.create',
|
|
'role.edit',
|
|
'role.destroy',
|
|
'role.manager',
|
|
|
|
// Menu
|
|
'menu.view',
|
|
'menu.create',
|
|
'menu.edit',
|
|
'menu.destroy',
|
|
'menu.manager',
|
|
];
|
|
|
|
foreach ($permissions as $name) {
|
|
Permission::firstOrCreate([
|
|
'name' => $name,
|
|
'guard_name' => 'admin',
|
|
]);
|
|
}
|
|
|
|
// Full Administrator nhận tất cả quyền
|
|
$fullAdmin = Role::where('name', 'Full Administrator')
|
|
->where('guard_name', 'admin')
|
|
->first();
|
|
|
|
if ($fullAdmin) {
|
|
$fullAdmin->syncPermissions(Permission::where('guard_name', 'admin')->get());
|
|
}
|
|
}
|
|
}
|