一键导入
logics-delete
Guide for creating DeleteLogics in the project
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for creating DeleteLogics in the project
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | logics-delete |
| description | Guide for creating DeleteLogics in the project |
| globs | app/Logics/**/*DeleteLogic.php |
This guide details how to create and use Logics within this project's ecosystem, specifically DeleteLogic. These components encapsulate the business logic for deleting records from the database and are used in controllers via dependency injection.
Logics are injected directly into controller methods along with Data Objects.
class UserController extends Controller
{
public function destroy(FlowByIdData $data, UserDeleteLogic $logic): JsonResponse
{
// Execute the logic's run method passing the received data
return $logic->run($data);
}
}
The main execution flow of a DeleteLogic follows this order:
before(): Pre-validations and business rules.action(): Business logic execution (finding the model and deleting it).after(): Additional logic after deletion (e.g., logging).response(): Returning the response with HTTP 204 No Content.before()Used for business rules or permissions. If it returns false, execution stops and an error is returned.
protected function before(): bool
{
if (! auth()->user()->can('delete_users')) {
return $this->error(
message: 'You do not have permission to delete users.',
status: Http::Forbidden
);
}
return true; // Continue execution
}
makeQuery()By default, DeleteLogic uses the model's remove() method if it exists, or searches by the id property from the input. You can override it to customize how the record is found.
protected function makeQuery(): Builder
{
// Custom way to find the record to delete
return $this->model->newQuery()
->where('uuid', $this->input->uuid);
}
after()Executed after the record has been deleted from the database.
protected function after(): bool
{
// Logic after deletion, e.g., logging
Log::info("User " . auth()->id() . " deleted user " . $this->model->id);
return true;
}
withResource()Allows returning data about the deleted resource (though standard 204 response usually doesn't have a body). In DeleteLogic, the response() method defaults to returning Http::NoContent.
class UserDeleteLogic extends DeleteLogic
{
public function __construct(User $model)
{
parent::__construct($model);
}
public function run(Data $input): JsonResponse
{
// The base class logic() method handles the lifecycle
return $this->logic($input);
}
protected function before(): bool
{
if ($this->model->isAdmin()) {
return $this->error('Admin users cannot be deleted');
}
return true;
}
}
Guide for creating API endpoints and routing using Logics
Guide for creating IndexLogics in the project
Guide for creating ShowLogics in the project
Guide for creating StoreLogics in the project
Guide for creating UpdateLogics in the project