PHPackages                             nguyenhiep/laravel-artisan-dispatchable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. nguyenhiep/laravel-artisan-dispatchable

ActiveLibrary[Queues &amp; Workers](/categories/queues)

nguyenhiep/laravel-artisan-dispatchable
=======================================

Dispatch Laravel jobs via Artisan

v1.2.3.2(5y ago)0140MITPHPPHP &gt;=7.4

Since Jun 14Pushed 5y agoCompare

[ Source](https://github.com/nguyenhiepvan/laravel-artisan-dispatchable)[ Packagist](https://packagist.org/packages/nguyenhiep/laravel-artisan-dispatchable)[ Docs](https://github.com/spatie/laravel-artisan-dispatchable)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/nguyenhiep-laravel-artisan-dispatchable/feed)WikiDiscussions main Synced yesterday

READMEChangelog (1)Dependencies (7)Versions (8)Used By (0)

Dispatch Laravel jobs via Artisan
=================================

[](#dispatch-laravel-jobs-via-artisan)

[![Latest Version on Packagist](https://camo.githubusercontent.com/facf99d6e207a897f752cab65280a4de99b98b1c6b9c49c7311a5359318e9de2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6172746973616e2d646973706174636861626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-artisan-dispatchable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/64152fa5fd9e0629373c0d0baaa056d72d3c0e3d335b9b7f4b087fae9e721b08/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6172746973616e2d646973706174636861626c652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/spatie/laravel-artisan-dispatchable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/923206fa9c096af017e43806b38a91ae8543ed2049215a4256839e9eb5f1a47e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d6172746973616e2d646973706174636861626c652f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/spatie/laravel-artisan-dispatchable/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/8e564425682a071ec66acc94d7591bc05001d624cb8d5adc2b5ce1c1004db516/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6172746973616e2d646973706174636861626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-artisan-dispatchable)

This package can register jobs as Artisan commands. All you need to do is let your job implement the empty `ArtisanDispatchable` interface.

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
    public function handle()
    {
        // perform some work...
    }
}
```

This allows the job to be executed via Artisan.

```
php artisan process-podcast
```

Why we created this package
---------------------------

[](#why-we-created-this-package)

[Laravel's scheduler](https://laravel.com/docs/master/scheduling#introduction) will perform all tasks sequentially. When you add a scheduled task to the scheduler, the task should perform its work as fast as possible, so no other tasks will have to wait.

If you have a task that needs to run every minute and its runtime is close to a minute, you should not use a simple Artisan command, as this will result in the delay of all other minute-ly tasks.

Long-running tasks should be performed by jobs that perform their work on the queue. Laravel has [the ability to schedule queued jobs](https://laravel.com/docs/master/scheduling#scheduling-queued-jobs). This way, those tasks will not block the scheduler.

```
$schedule->job(new ProcessPodcast)->everyFiveMinutes();
```

The downside of this approach is that you cannot run that job via Artisan anymore. You have to choose between using an artisan command + blocking the scheduler on the one hand, and job + not blocking the scheduler on the other hand.

Using our package, you don't have to make that choice anymore. When letting your job implement `Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable`, you will not block the scheduler and can still execute the logic via Artisan.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/6db47b8e88df7f00a2ab261cca77d9a0ca64e26f87b0313b1bee638e2e93622a/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6172746973616e2d646973706174636861626c652e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-artisan-dispatchable)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require nguyenhiep/laravel-artisan-dispatchable
```

Optionally, you can publish the config file with:

```
php artisan vendor:publish --provider="Spatie\ArtisanDispatchable\ArtisanDispatchableServiceProvider" --tag="artisan-dispatchable-config"
```

This is the contents of the published config file:

```
return [
    /*
     * These directories will be scanned for dispatchable jobs. They
     * will be registered automatically to Artisan.
     */
    'auto_discover_dispatchable_jobs' => [
        app()->path(),
    ],

    /*
     * This directory will be used as the base path when scanning
     * for dispatchable jobs.
     */
    'auto_discover_base_path' => base_path(),

    /*
     * In production, you likely don't want the package to auto-discover dispatchable
     * jobs every time Artisan is invoked. The package can cache discovered job.
     *
     * Here you can specify where the cache should be stored.
     */
    'cache_file' => storage_path('app/artisan-dispatchable/artisan-dispatchable-jobs.php'),

    /**
     * Here you can specify the prefix to be used for all dispatchable jobs.
     */
    'command_name_prefix' => '',
];
```

Usage
-----

[](#usage)

All you need to do is let your job implement the empty `ArtisanDispatchable` interface.

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
    public function handle()
    {
        // perform some work...
    }
}
```

This allows the job to be executed via Artisan.

```
php artisan process-podcast
```

This job will not be queued, but will be immediately executed inside the executed artisan command.

### Queueing jobs via Artisan

[](#queueing-jobs-via-artisan)

If you want to put your job on the queue instead of executing it immediately, add the `queued` option.

```
php artisan process-podcast --queued
```

### Passing arguments to a job

[](#passing-arguments-to-a-job)

If your job has constructor arguments, you may pass those arguments via options on the artisan command.

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
    public function __construct(
        string $myFirstArgument,
    ) {}

    public function handle()
    {
        // perform some work...
    }
}
```

Via artisan, you can call the job like this

```
php artisan process-podcast --my-first-argument="My string value"
```

### Using Eloquent models as arguments

[](#using-eloquent-models-as-arguments)

If your job argument is an eloquent model, you may pass the id of the model to the artisan command option.

```
use App\Models\Podcast;
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
    public function __construct(
        Podcast $podcast,
    ) {}

    public function handle()
    {
        // perform some work...
    }
}
```

Here's how you can execute this job with podcast id `1234`

```
php artisan process-podcast --podcast="1234"
```

### Customizing the name of the command

[](#customizing-the-name-of-the-command)

By default, the artisan command name of a job, is the base name of job in kebab-case.

You can set a custom name by setting a property named `artisanName` on your job.

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
     public string $artisanName = 'my-app:process-my-podcast';

    public function handle()
    {
        // perform some work...
    }
}
```

This job can now be executed with this command:

```
php artisan my-app:process-my-podcast
```

### Customizing the description of the command

[](#customizing-the-description-of-the-command)

To add a description to the list of artisan commands, add a property `$artisanDescription` to your job.

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;

class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
    public string $artisanDescription = 'This a custom description';

    public function handle()
    {
        // perform some work...
    }
}
```

### Prefixing all commands

[](#prefixing-all-commands)

You can specify a prefix in the `command_name_prefix` key of the config file. When this is for example set to `my-custom-prefix`, then you would be able to call `MyDispatchableJob` with this command:

```
php artisan my-custom-prefix:process-my-podcast
```

### Caching discovered jobs

[](#caching-discovered-jobs)

This package can automatically discover jobs that implement `ArtisanDispatchable` and what their artisan command should be through looping through all classes and performing some reflection. In a local environment this is perfect, as the performance hit is not too bad, and you don't have to do anything special besides letting your job implement `ArtisanDispatchable`.

In a production environment, you probably don't want to loop through all classes on every request. The package contains a command to cache all discovered jobs.

```
php artisan artisan-dispatchable:cache-artisan-dispatchable-jobs
```

You probably want to call that command during your deployment of your app. This will create cache file at the location specified in the `cache_file` key of the `artisan-dispatchable` config file.

Should you want to clear the cache, you can execute this command:

```
php artisan artisan-dispatchable:clear-artisan-dispatchable-jobs
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

7

Last Release

1829d ago

Major Versions

0.0.1 → 1.0.02021-06-14

PHP version history (2 changes)0.0.1PHP ^8.0

v1.2.3PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ee7ece29e66e7029d6b12d947a7d9714ae36346f21e92d767cfc797b86949d8?d=identicon)[nguyenhiepvan](/maintainers/nguyenhiepvan)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (73 commits)")[![nguyenhiepvan](https://avatars.githubusercontent.com/u/33170716?v=4)](https://github.com/nguyenhiepvan "nguyenhiepvan (6 commits)")[![pkboom](https://avatars.githubusercontent.com/u/13960169?v=4)](https://github.com/pkboom "pkboom (2 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (2 commits)")[![abenerd](https://avatars.githubusercontent.com/u/7523903?v=4)](https://github.com/abenerd "abenerd (1 commits)")[![noplanman](https://avatars.githubusercontent.com/u/9423417?v=4)](https://github.com/noplanman "noplanman (1 commits)")

---

Tags

spatielaravellaravel-artisan-dispatchable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nguyenhiep-laravel-artisan-dispatchable/health.svg)

```
[![Health](https://phpackages.com/badges/nguyenhiep-laravel-artisan-dispatchable/health.svg)](https://phpackages.com/packages/nguyenhiep-laravel-artisan-dispatchable)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M167](/packages/spatie-laravel-health)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
