mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 17:24:10 +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:
@@ -92,10 +92,17 @@ class User extends Authenticatable implements HasMedia
|
||||
|
||||
public function getFormattedCreatedAtAttribute($value)
|
||||
{
|
||||
$company_id = (CompanySetting::where('company_id', request()->header('company'))->exists())
|
||||
? request()->header('company')
|
||||
: $this->companies()->first()->id;
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $company_id);
|
||||
$companyId = request()->header('company');
|
||||
|
||||
if (! $companyId || ! CompanySetting::where('company_id', $companyId)->exists()) {
|
||||
$firstCompany = $this->companies()->first();
|
||||
if (! $firstCompany) {
|
||||
return Carbon::parse($this->created_at)->format('Y-m-d');
|
||||
}
|
||||
$companyId = $firstCompany->id;
|
||||
}
|
||||
|
||||
$dateFormat = CompanySetting::getSetting('carbon_date_format', $companyId);
|
||||
|
||||
return Carbon::parse($this->created_at)->format($dateFormat);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user