with one click
logics-delete
Guide for creating DeleteLogics in the project
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Guide for creating DeleteLogics in the project
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
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
| 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;
}
}