65 lines
1.2 KiB
PHP
65 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
final class Customer extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'company_name',
|
|
'type',
|
|
'email',
|
|
'phone',
|
|
'address',
|
|
'city',
|
|
'postal_code',
|
|
'country',
|
|
'notes',
|
|
'is_portal_enabled',
|
|
'user_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'is_portal_enabled' => 'boolean',
|
|
];
|
|
}
|
|
|
|
// Relationships
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(Event::class);
|
|
}
|
|
|
|
// Helper methods
|
|
|
|
public function isCompany(): bool
|
|
{
|
|
return $this->type === 'company';
|
|
}
|
|
|
|
public function displayName(): string
|
|
{
|
|
return $this->company_name ?? $this->name;
|
|
}
|
|
}
|
|
|