2022-08-13 06:04:47 +00:00
|
|
|
<?php
|
|
|
|
|
2022-08-13 06:12:37 +00:00
|
|
|
namespace App\Models\WorkOrder;
|
2022-08-13 06:04:47 +00:00
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Reply extends Model
|
|
|
|
{
|
|
|
|
use HasFactory;
|
|
|
|
|
2022-08-15 14:29:57 +00:00
|
|
|
protected $table = 'work_order_replies';
|
2022-08-13 06:12:37 +00:00
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'content',
|
|
|
|
'work_order_id',
|
2022-08-15 14:29:57 +00:00
|
|
|
// 'user_id',
|
2022-08-13 06:12:37 +00:00
|
|
|
'is_pending',
|
|
|
|
];
|
|
|
|
|
2022-08-15 14:29:57 +00:00
|
|
|
public function workOrder()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(WorkOrder::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scopeWorkOrderId($query, $work_order_id)
|
|
|
|
{
|
|
|
|
return $query->where('work_order_id', $work_order_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// before create
|
|
|
|
protected static function boot()
|
|
|
|
{
|
|
|
|
parent::boot();
|
|
|
|
static::creating(function ($model) {
|
|
|
|
|
|
|
|
// load work order
|
|
|
|
$model->load(['workOrder']);
|
|
|
|
// change work order status
|
|
|
|
if (auth('sanctum')->check()) {
|
|
|
|
$model->user_id = auth()->id();
|
|
|
|
$model->workOrder->status = 'user_replied';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth('remote')->check()) {
|
|
|
|
$model->user_id = null;
|
|
|
|
$model->workOrder->status = 'replied';
|
|
|
|
}
|
|
|
|
|
|
|
|
$model->workOrder->save();
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-08-13 06:04:47 +00:00
|
|
|
}
|