diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 22e442e6..7d7348af 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -4,6 +4,8 @@ namespace App\Http\Resources; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; class CompanyResource extends JsonResource { @@ -33,6 +35,23 @@ class CompanyResource extends JsonResource return new UserResource($this->owner); }), 'roles' => RoleResource::collection($this->roles), + 'user_role' => $this->getUserRoleTitle(), ]; } + + private function getUserRoleTitle(): ?string + { + $user = Auth::user(); + + if (! $user) { + return null; + } + + return DB::table('assigned_roles') + ->join('roles', 'roles.id', '=', 'assigned_roles.role_id') + ->where('assigned_roles.entity_id', $user->id) + ->where('assigned_roles.entity_type', get_class($user)) + ->where('assigned_roles.scope', $this->id) + ->value('roles.title'); + } } diff --git a/resources/scripts-v2/layouts/partials/CompanySwitcher.vue b/resources/scripts-v2/layouts/partials/CompanySwitcher.vue index d90e6628..0e8012d0 100644 --- a/resources/scripts-v2/layouts/partials/CompanySwitcher.vue +++ b/resources/scripts-v2/layouts/partials/CompanySwitcher.vue @@ -109,6 +109,9 @@