Files
Nexora/app/Models/Company.php
2025-10-25 11:29:20 +02:00

66 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Company extends Model
{
use HasFactory, SoftDeletes;
protected $fillable = [
'name',
'commercial_name',
'status',
'address',
'postal_code',
'city',
'country',
'phone',
'email',
'cif',
'logo'
];
protected $casts = [
'created_at' => 'datetime:d/m/Y H:i',
'updated_at' => 'datetime:d/m/Y H:i',
];
public function getStatusColorAttribute()
{
return [
'active' => 'bg-green-100 text-green-800',
'closed' => 'bg-red-100 text-red-800',
][$this->status] ?? 'bg-gray-100 text-gray-800';
}
public function getStatusTextAttribute()
{
return [
'active' => 'Activo',
'closed' => 'Cerrado',
][$this->status] ?? 'Desconocido';
}
public function contacts(): BelongsToMany
{
return $this->belongsToMany(User::class, 'company_contacts')
->withPivot('position')
->withTimestamps();
}
public function users()
{
return $this->hasMany(User::class);
}
public function projects()
{
return $this->hasMany(Project::class);
}
}