PHP code example of raicem / laravel-defer-jobs

1. Go to this page and download the library: Download raicem/laravel-defer-jobs 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/ */

    

raicem / laravel-defer-jobs example snippets


// app/Http/Kernel.php
 protected $middleware = [
     //..
    \App\Http\Middleware\TrustProxies::class,
    \Raicem\Defer\Middleware\ExecuteDeferredJobs::class,
];

php artisan make:job LogSomething

use Raicem\Defer\Deferrable;

class LogSomething implements ShouldQueue
{
    use Deferrable, SerializesModels;

    private $message;
    
    public function __construct(string $message)
    {
        $this->message = $message;
    }

    public function handle()
    {
        // handle job
    }
}

// HomeController.php

use App\Jobs\LogSomething;

class HomeController 
{
    public function action()
    {
        // do stuff
        LogSomething::defer('my log message');

        return view('welcome');
    }
}