PHP code example of spatie / laravel-artisan-dispatchable
1. Go to this page and download the library: Download spatie/laravel-artisan-dispatchable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spatie / laravel-artisan-dispatchable example snippets
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;
class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
public function handle()
{
// perform some work...
}
}
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' => '',
];
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\ArtisanDispatchable\Jobs\ArtisanDispatchable;
class ProcessPodcast implements ShouldQueue, ArtisanDispatchable
{
public function handle()
{
// perform some work...
}
}
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...
}
}
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...
}
}
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...
}
}
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...
}
}