43 lines
949 B
PHP
43 lines
949 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class FieldJob extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'field_job_setting_id',
|
|
'asigned_user_id',
|
|
'start_date',
|
|
'end_date',
|
|
];
|
|
|
|
protected $casts = [
|
|
'start_date' => 'date',
|
|
'end_date' => 'date',
|
|
];
|
|
|
|
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');
|
|
}
|
|
}
|