64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class FieldJob extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'field_job_setting_id',
|
|
'asigned_user_id',
|
|
'user_id',
|
|
'contract_id',
|
|
'assigned_at',
|
|
'completed_at',
|
|
'cancelled_at',
|
|
'priority',
|
|
'notes',
|
|
'address_snapshot ',
|
|
];
|
|
|
|
protected $casts = [
|
|
'assigned_at' => 'date',
|
|
'completed_at' => 'date',
|
|
'cancelled_at' => 'date',
|
|
'priority' => 'boolean',
|
|
'address_snapshot ' => 'array',
|
|
];
|
|
|
|
protected static function booted(){
|
|
static::creating(function (FieldJob $fieldJob) {
|
|
if(!isset($fieldJob->user_id)){
|
|
$fieldJob->user_id = auth()->id();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function setting(): BelongsTo
|
|
{
|
|
return $this->belongsTo(FieldJobSetting::class, 'field_job_setting_id');
|
|
}
|
|
|
|
public function assignedUser(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'asigned_user_id');
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
public function contract(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Contract::class, 'contract_id');
|
|
}
|
|
}
|