store-manage/app/Traits/HasCheckable.php

36 lines
748 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 $check_key = '';
protected static function booted(): void
{
static::created(function ($model) {
// 创建审核申请
$model->workflow()->create([
'key' => $model->getCheckKey(),
]);
});
}
public function getCheckKey()
{
return $this->check_key ?: Str::snake(class_basename(__CLASS__));
}
/**
* 关联审核流水
*/
public function workflow()
{
return $this->morphOne(WorkflowCheck::class, 'subject');
}
}