36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Admin\Controllers;
|
|
|
|
use App\Enumerations\UserRole;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Scopes\CommonController;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class UserDetailGetController extends CommonController
|
|
{
|
|
public function __invoke(int $id, Request $request): JsonResponse
|
|
{
|
|
$user = User::findOrFail($id);
|
|
|
|
$userData = $user->toArray();
|
|
|
|
unset($userData['password'], $userData['remember_token'], $userData['activation_token'], $userData['activation_token_expires_at']);
|
|
|
|
$tenantNames = Tenant::pluck('name', 'slug');
|
|
$userData['nicename'] = $user->getNicename();
|
|
$userData['fullname'] = $user->getFullName();
|
|
$userData['local_group_name'] = $tenantNames[$user->local_group] ?? $user->local_group;
|
|
|
|
return response()->json([
|
|
'user' => $userData,
|
|
'isOwnUser' => auth()->id() === $user->id,
|
|
'isLvTenant' => $this->tenant->slug === 'lv',
|
|
'userRoles' => UserRole::all()->map(fn($role) => ['slug' => $role->slug, 'name' => $role->name]),
|
|
'localGroups' => Tenant::where('is_active_local_group', true)->get()->map(fn($t) => ['slug' => $t->slug, 'name' => $t->name]),
|
|
]);
|
|
}
|
|
}
|