repuve-backend-v1/app/Models/VehicleTagLog.php

75 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class VehicleTagLog extends Model
{
use HasFactory;
protected $table = 'vehicle_tags_logs';
protected $fillable = [
'vehicle_id',
'tag_id',
'folio_anterior',
'action_type',
'cancellation_reason_id',
'cancellation_observations',
'cancellation_at',
'cancelled_by',
'performed_by',
];
protected function casts(): array
{
return [
'cancellation_at' => 'datetime',
];
}
public function vehicle() {
return $this->belongsTo(Vehicle::class);
}
public function tag() {
return $this->belongsTo(Tag::class);
}
public function cancelledBy() {
return $this->belongsTo(User::class, 'cancelled_by');
}
public function performedBy() {
return $this->belongsTo(User::class, 'performed_by');
}
public function cancellationReason()
{
return $this->belongsTo(CatalogCancellationReason::class, 'cancellation_reason_id');
}
public function isInscription()
{
return $this->action_type === 'sustitucion_primera_vez';
}
public function isUpdate()
{
return $this->action_type === 'actualizacion';
}
public function isSubstitution()
{
return $this->action_type === 'sustitucion';
}
public function isCancellation()
{
return $this->action_type === 'cancelacion';
}
}