62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Scopes\OrganisationScope;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
final class Company extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
use SoftDeletes;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new OrganisationScope());
|
|
}
|
|
|
|
protected $fillable = [
|
|
'organisation_id',
|
|
'name',
|
|
'type',
|
|
'contact_first_name',
|
|
'contact_last_name',
|
|
'contact_email',
|
|
'contact_phone',
|
|
];
|
|
|
|
public function getContactFullNameAttribute(): ?string
|
|
{
|
|
if (! $this->contact_first_name) {
|
|
return null;
|
|
}
|
|
|
|
return trim("{$this->contact_first_name} {$this->contact_last_name}");
|
|
}
|
|
|
|
public function organisation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organisation::class);
|
|
}
|
|
|
|
public function persons(): HasMany
|
|
{
|
|
return $this->hasMany(Person::class);
|
|
}
|
|
|
|
/** @param Builder<self> $query */
|
|
public function scopeOrdered(Builder $query): Builder
|
|
{
|
|
return $query->orderBy('name');
|
|
}
|
|
}
|