store-manage/app/Traits/HasCheckable.php

39 lines
802 B
PHP

<?php
namespace App\Traits;
use App\Enums\CheckStatus;
use App\Models\{WorkflowCheck, Employee};
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
trait HasCheckable
{
protected static function booted(): void
{
static::created(function ($model) {
// 创建审核申请
$model->workflow()->create([
'key' => $model->getCheckKey(),
]);
});
}
public function getCheckKey(): string
{
if (property_exists($this, 'checkKey')) {
return $this->checkKey;
}
return Str::snake(class_basename(__CLASS__));
}
/**
* 关联审核流水
*/
public function workflow()
{
return $this->morphOne(WorkflowCheck::class, 'subject');
}
}