mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-17 10:14:08 +00:00
Handle no-company user in ScopeBouncer middleware and User model
Skip bouncer scoping when user has no companies instead of crashing on null. Fall back to Y-m-d date format in getFormattedCreatedAtAttribute when no company settings are available. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,11 +32,17 @@ class ScopeBouncer
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
$tenantId = $request->header('company')
|
||||
? $request->header('company')
|
||||
: $user->companies()->first()->id;
|
||||
$company = $request->header('company');
|
||||
|
||||
$this->bouncer->scope()->to($tenantId);
|
||||
if (! $company) {
|
||||
$firstCompany = $user->companies()->first();
|
||||
if (! $firstCompany) {
|
||||
return $next($request);
|
||||
}
|
||||
$company = $firstCompany->id;
|
||||
}
|
||||
|
||||
$this->bouncer->scope()->to($company);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user