add role permission logic
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Roles;
|
||||
|
||||
use App\Models\UserRole;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class RoleSwitchService
|
||||
{
|
||||
public function __construct(private RoleDashboardService $dashboardService)
|
||||
{
|
||||
}
|
||||
|
||||
public function getUserRoleNames(int $userId): array
|
||||
{
|
||||
$roles = UserRole::getRolesByUserId($userId);
|
||||
return array_values(array_filter(array_map(fn ($r) => (string) ($r['role_name'] ?? ''), $roles)));
|
||||
}
|
||||
|
||||
public function switchRole(string $role): string
|
||||
{
|
||||
Session::put('active_role', $role);
|
||||
return $this->dashboardService->bestDashboardRouteFor([$role]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user