2025-10-28 18:03:44 +03:00

55 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Fournisseur extends Model
{
protected $fillable = [
'name',
'vat_number',
'siret',
'email',
'phone',
'billing_address_line1',
'billing_address_line2',
'billing_postal_code',
'billing_city',
'billing_country_code',
'notes',
'is_active',
'user_id',
];
protected $casts = [
'is_active' => 'boolean',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function commercial(): ?string
{
return $this->user ? $this->user->name : 'Système';
}
/**
* Get the full billing address as a string.
*/
public function getBillingAddressAttribute(): ?string
{
$parts = array_filter([
$this->billing_address_line1,
$this->billing_address_line2,
$this->billing_postal_code ? $this->billing_postal_code . ' ' . $this->billing_city : $this->billing_city,
$this->billing_country_code,
]);
return !empty($parts) ? implode(', ', $parts) : null;
}
}