Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/Controller.php
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | public static function errorResponse(int $code, string $message = null, array $data = []) | ||||
if (!empty($data)) { | if (!empty($data)) { | ||||
$response = $response + $data; | $response = $response + $data; | ||||
} | } | ||||
return response()->json($response, $code); | return response()->json($response, $code); | ||||
} | } | ||||
/** | /** | ||||
* Check if current user has access to the specified object | |||||
* by being an admin or existing in the same tenant context. | |||||
* | |||||
* @param ?object $object Model object | |||||
* | |||||
* @return bool | |||||
*/ | |||||
protected function checkTenant(object $object = null): bool | |||||
{ | |||||
if (empty($object)) { | |||||
return false; | |||||
} | |||||
$user = $this->guard()->user(); | |||||
if ($user->role == 'admin') { | |||||
return true; | |||||
} | |||||
return $object->tenant_id == $user->tenant_id; | |||||
} | |||||
/** | |||||
* Get the guard to be used during authentication. | * Get the guard to be used during authentication. | ||||
* | * | ||||
* @return \Illuminate\Contracts\Auth\Guard | * @return \Illuminate\Contracts\Auth\Guard | ||||
*/ | */ | ||||
protected function guard() | protected function guard() | ||||
{ | { | ||||
return Auth::guard(); | return Auth::guard(); | ||||
} | } | ||||
} | } |