PHP code example of spatie / laravel-interacts-with-payload
1. Go to this page and download the library: Download spatie/laravel-interacts-with-payload 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-interacts-with-payload example snippets
// typically in a service provider
use Spatie\InteractsWithPayload\Facades\AllJobs;
AllJobs::add('user', fn() => auth()->user());
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\InteractsWithPayload\Concerns\InteractsWithPayload;
class YourJob implements ShouldQueue
{
use InteractsWithPayload;
public function handle()
{
// instance of User model or `null`
$user = $this->getFromPayload('user');
}
}
use Spatie\InteractsWithPayload\Facades\AllJobs;
AllJobs::add('extraValue', fn() => 'My extra value')
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\InteractsWithPayload\Concerns\InteractsWithPayload;
class YourJob implements ShouldQueue
{
use InteractsWithPayload;
public function handle()
{
// will contain "My extra value"
$value = $this->getFromPayload('extraValue');
}
}
use Spatie\InteractsWithPayload\Facades\AllJobs;
AllJobs::add('user', fn() => auth()->user())
use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\InteractsWithPayload\Concerns\InteractsWithPayload;
class YourJob implements ShouldQueue
{
use InteractsWithPayload;
public function handle()
{
// instance of User model or `null` if the user has been deleted in the meantime
$user = $this->getFromPayload('user');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.