| Package Data | |
|---|---|
| Maintainer Username: | mxl |
| Maintainer Contact: | mledin89@gmail.com (Michael Ledin) |
| Package Create Date: | 2019-09-26 |
| Package Last Update: | 2025-02-25 |
| Home Page: | |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-10-27 15:04:04 |
| Package Statistics | |
|---|---|
| Total Downloads: | 1,171,568 |
| Monthly Downloads: | 27,498 |
| Daily Downloads: | 897 |
| Total Stars: | 66 |
| Total Watchers: | 1 |
| Total Forks: | 7 |
| Total Open Issues: | 1 |
Laravel job tools:
Job base class with boilerplate.$ composer require mxl/laravel-job
Laravel 5.5+ will use the auto-discovery feature to add MichaelLedin\LaravelJob\LaravelJobServiceProvider::class to providers.
This package is not compatible with older Laravel versions.
Make sure that you either use sync connection (see default property in config/queue.php) or run queue worker:
$ php artisan queue:work
Then dispatch command with:
$ php artisan job:dispatch YourJob
if YourJob class is located under \App\Jobs or specify full class name with namespace:
$ php artisan job:dispatch '\Path\To\YourJob'
If you want to run job right now without posting it to queue use job:dispatchNow command:
$ php artisan job:dispatchNow YourJob
$ php artisan job:dispatch YourJob John 1990-01-01
John and 1990-01-01 values will be passed to YourJob constructor as $name and $birthDate arguments:
class YourJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
__constructor($name, $birthDate)
{
// ...
}
public function handle()
{
// ...
}
}
Often a job is already in use somewhere from PHP code and if it has constructor arguments that must have specific type, then it can be required to parse command line parameters.
For this purpose implement FromParameters interface:
use MichaelLedin\LaravelJob\FromParameters;
use Carbon\Carbon;
class YourJob implements ShouldQueue, FromParameters
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
__constructor(string $name, Carbon $birthDate)
{
// ...
}
public function handle()
{
// ...
}
public static function fromParameters(...$parameters)
{
return new self($parameters[0], Carbon::parse($parameters[1]));
}
}
Job classes always use the same interface ShouldQueue and Dispatchable, InteractsWithQueue, Queueable, SerializesModels traits.
To avoid such boilerplate your jobs can extend MichaelLedin\LaravelJob\Job class:
use MichaelLedin\LaravelJob\Job;
use Carbon\Carbon;
class YourJob extends Job
{
// ...
}
It also includes default FromParameters interface implementation that is equivalent to calling constructor with arguments provided by command line parameters without any parsing.
To add parsing override fromParameters method.
See the LICENSE file for details.