'like', 'role_id' => '=' ]; protected $hidden = ['pivot']; /** * @var bool */ protected bool $asTree = true; /** * @var string[] */ protected $casts = [ 'type' => MenuType::class, 'status' => MenuStatus::class ]; /** * is hidden * * @return bool */ public function isHidden(): bool { return $this->hidden === Status::Disable; } /** * action type * * @return bool */ public function isAction(): bool { return $this->type == MenuType::Action; } /** * actions * * @return HasMany */ public function actions(): HasMany { return $this->hasMany(self::class, 'parent_id', 'id')->where('type', MenuType::Action); } /** * * @param array $data * @return bool */ public function storeBy(array $data): bool { $model = $this->fill($data); if ($model->isAction()) { $parentMenu = $this->firstBy($model->parent_id, 'id'); $model->setAttribute('module', $parentMenu->module); $model->setAttribute('permission_mark', $parentMenu->permission_mark . '@' . $data['permission_mark']); $model->setAttribute('route', ''); $model->setAttribute('icon', ''); $model->setAttribute('component', ''); $model->setAttribute('redirect', ''); return $model->setCreatorId()->save(); } else { return parent::storeBy($data); } } }