PHP code example of itsemon245 / laravel-pausable-job

1. Go to this page and download the library: Download itsemon245/laravel-pausable-job 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/ */

    

itsemon245 / laravel-pausable-job example snippets


//Other imports
 use Itsemon245\PausableJob\Traits\Pausable;

class EmailJob implements ShouldQueue
{
  // Other Traits
   use Pausable;

    public function __construct(public Campaign $campaign)
    {
        /**
         * Set or bind which model is responsible to pause the job
         */
        $this->setPausedBy($campaign);
    }
}

//Other imports
 use Itsemon245\PausableJob\Traits\HasPausableJobs;

class Campaign extends Model
{
    //Other traits
   use HasPausableJobs;
}

class CampaignController extends Controller{

  public function pause(Campaign $campaign){
    //Immediately pause all jobs that are related to this campaign 
    $campaign->pauseJobs();
  
    return back();
  }
  
  public function resume(Campaign $campaign){
  // Resume jobs whenever you want
   $campaign->resumeJobs();
  }

}
bash
php artisan vendor:publish --provider="Itsemon245\PausableJob\PausableJobServiceProvider"
php artisan migrate