βš™οΈActions

Classes that take care of one specific task.

This package introduces a new way of organizing the logic of your Maginium applications by focusing on the actions your applications provide.

Instead of creating controllers, jobs, listeners, and so on, it allows you to create a PHP class that handles a specific task and run that class as anything you want.

Resolves the action from the container.

MyAction::make();

// Equivalent to:
app(MyAction::class);

Resolves and executes the action.

Resolves and executes the action if the condition is met.

Resolves and executes the action if some condition is not met.

Executes the action by delegating immediately to the handle method.

Whilst this method is not used, it has to be defined on the action to register the action as an invokable controller. When missing, Maginium will throw an exception warning us that we're trying to register a class as an invokable controller without the __invoke method. The truth is, the controller will be an instance of ControllerDecorator but the framework doesn't know that yet.

If you need to use the __invoke method for something else, you may override it (opens a new window)arrow-up-right with anything you want. The only requirement is that a __invoke method has to exist.

#arrow-up-rightMethods used

Lists all methods recognized and used by the ControllerDecorator

#arrow-up-rightasController

It is called when used as an invokable controller. Uses the handle method directly when no asController method exists.

#arrow-up-rightjsonResponse

Called after the asController method when the request expects JSON. The first argument is the return value of the asController method and the second argument is the request itself.

#arrow-up-righthtmlResponse

Called after the asController method when the request expects HTML. The first argument is the return value of the asController method and the second argument is the request itself.

#arrow-up-rightgetControllerMiddleware

Adds controller middleware directly in the action.

#arrow-up-rightprepareForValidation

Called right before authorization and validation is resolved.

Defines authorization logic for the controller.

You may also return gate responses instead of booleans.

Provides the validation rules for the controller.

#arrow-up-rightwithValidator

Adds custom validation logic to the existing validator.

#arrow-up-rightafterValidator

Adds an after callback to the existing validator. The example below is equivalent to the example provided in the withValidator method.

#arrow-up-rightgetValidator

DefineDefines your validator instead of the default one generated using rules, withValidator, etc.

#arrow-up-rightgetValidationData

Defines the data that should be used for validation. Defaults to: $request->all().

#arrow-up-rightgetValidationMessages

Customize the messages of your validation rules.

#arrow-up-rightgetValidationAttributes

Provides some human-friendly mapping to your request attributes.

#arrow-up-rightgetValidationRedirect

Customises the redirect URL when validation fails. Defaults to redirecting back to the previous page.

#arrow-up-rightgetValidationErrorBag

Customises the validator's error bag when validation fails. Defaults to: default.

#arrow-up-rightgetValidationFailure

Overrides the validation failure altogether. Defaults to: ValidationException.

#arrow-up-rightgetAuthorizationFailure

Overrides the authorization failure. Defaults to: AuthorizationException.

Last updated