add all controllers logic

This commit is contained in:
root
2026-03-11 17:53:15 -04:00
parent 3e6c577085
commit 2ef71cc92b
421 changed files with 12009 additions and 5211 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace App\Services\Auth;
use Illuminate\Support\Facades\DB;
class UserRoleService
{
public function getRoleIds(int $userId): array
{
return DB::table('user_roles')
->where('user_id', $userId)
->whereNull('deleted_at')
->pluck('role_id')
->map(fn ($id) => (int) $id)
->all();
}
public function hasPermissionForCrud(array $roleIds, string $permissionName, string $crudAction = 'read'): bool
{
if (empty($roleIds)) {
return false;
}
$rows = DB::table('role_permissions as rp')
->join('permissions as p', 'p.id', '=', 'rp.permission_id')
->whereIn('rp.role_id', $roleIds)
->where('p.name', $permissionName)
->select('rp.can_create', 'rp.can_read', 'rp.can_update', 'rp.can_delete', 'rp.can_manage')
->get();
foreach ($rows as $row) {
$manage = (bool) ($row->can_manage ?? false);
if ($manage) {
return true;
}
if ($crudAction === 'create' && !empty($row->can_create)) {
return true;
}
if ($crudAction === 'read' && !empty($row->can_read)) {
return true;
}
if ($crudAction === 'update' && !empty($row->can_update)) {
return true;
}
if ($crudAction === 'delete' && !empty($row->can_delete)) {
return true;
}
}
return false;
}
}