mejoras en la gestión de proyectos y documentos: se añaden nuevos campos y validaciones para optimizar la organización y el seguimiento de los mismos.
This commit is contained in:
65
app/Models/Company.php
Normal file
65
app/Models/Company.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user