Download the PHP package victor-falcon/laravel-task without Composer
On this page you can find all versions of the php package victor-falcon/laravel-task. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download victor-falcon/laravel-task
More information about victor-falcon/laravel-task
Files in victor-falcon/laravel-task
Package laravel-task
Short Description A simple laravel task trigger
License MIT
Informations about the package laravel-task
🇪🇸 Documentación en español aqui
Table of content:
- Installation
- Usage
- Basic usage
- With validation
- With authorization
- Recover response
- Generate IDE Help
- Credits
Installation
Install via composer
Usage
1. Basic usage
Create a simple task using:
You can pass Shop/CreateUserShop to create the class in a sub-folder or just the task name. The default path is
app/Tasks
.
and trigger it:
2. With validation
If you want, you can pass validated data to your tasks using the Laravel validator. For example, If you need to validate a user creation you can do something like this.
And then you can trigger your task with extra data using:
You can customize the messages with the method messages(): array
in your task or add custom attributes with customAttributes(): array
.
If you want to customize the errors bag name of the validator just define the string $errorBag
property in your class.
3. With authorization
Sometimes you need to check if the user triggering the task is authorized or not. You can do that by adding a simple authorize(): bool
method to your task. If this method returns false
an AuthorizationException
will thrown on before execution.
In any task you can access to the current logged user with $this->user()
or, if you want, you can pass a user object by doing:
4. Recover response
By default, each task is executed without returning any value. So if you want to recover the result of a task you must call the result()
method.
Generate IDE Help
In order to make more easy to write and use your task you can generate a _ide_helper_tasks.php
file automatically with the artisan task:ide-help
command.
Update config
If you want, you can publish the package config to customize, for example, where do you want you task to be store at: