优化 代码
This commit is contained in:
parent
3ce254aa44
commit
8f85d28a10
@ -71,14 +71,11 @@ protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::creating(function ($model) {
|
||||
|
||||
$model->is_pending = 1;
|
||||
|
||||
|
||||
// load work order
|
||||
$model->load(['workOrder']);
|
||||
|
||||
|
||||
throw_if($model->workOrder->status == 'pending' || $model->workOrder->status == 'error', CommonException::class, '工单状态不正确');
|
||||
|
||||
// change work order status
|
||||
|
@ -10,6 +10,8 @@
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* App\Models\WorkOrder\WorkOrder
|
||||
@ -65,7 +67,7 @@
|
||||
*/
|
||||
class WorkOrder extends Model
|
||||
{
|
||||
use HasFactory, Cachable;
|
||||
use Cachable;
|
||||
|
||||
protected $table = 'work_orders';
|
||||
|
||||
@ -122,6 +124,9 @@ protected static function boot()
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CommonException
|
||||
*/
|
||||
public function safeDelete(): bool
|
||||
{
|
||||
if ($this->status == 'pending') {
|
||||
@ -135,26 +140,26 @@ public function safeDelete(): bool
|
||||
|
||||
// replies
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
// host
|
||||
|
||||
public function replies(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
public function replies(): HasMany
|
||||
{
|
||||
return $this->hasMany(Reply::class);
|
||||
}
|
||||
|
||||
public function host(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
public function host(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Host::class);
|
||||
}
|
||||
|
||||
// scope
|
||||
|
||||
public function module(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
public function module(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Module::class);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user