New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

spatie/laravel-interacts-with-payload

Add variables to the payloads of all jobs in a Laravel app
97,791 68

Larablocks Analysis

Compatibility

Trusted maintainer

spatie/laravel-interacts-with-payload works with Laravel 13 (latest release 1.3.0, Nov 6, 2026).

Laravel 8 to 12 in earlier releases.

  • Trusted maintainer: spatie publishes 287 packages on Larablocks, with 204,136,623 downloads a month between them.

Recommendation checks

Solid choice

Solid choice: maintained and up to date, meets 2 of 4 checks; below the bar for Recommended on use.

  • Works with Laravel 13, the current version
  • Released in the last 12 months (Nov 6, 2026)
  • 2,915 downloads a month (needs 10,000)
  • 68 GitHub stars (needs 100)

State

Maintained
  • Last stable release: Nov 6, 2026.
  • 1 release in the last 12 months.
  • First released: Apr 15, 2021.
  • Monthly downloads: 2,915, up 70% from six months ago.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 1, 2026.

Install
composer require spatie/laravel-interacts-with-payload
Latest Version:1.3.0
PHP:^8.3
Laravel:13
Older releases:8 – 12
License:MIT
Last Updated:Nov 6, 2026
Links: GitHub  ·  Packagist
Maintainer: spatie

Inject extra info to the payloads of all jobs in a Laravel app

Latest Version on Packagist run-tests Total Downloads

This package makes it easy to inject things in every job.

Imagine that you want to have the user who initiated the queued of a job available in every queued job. This is how you would implement that using this package.

// typically in a service provider

use Spatie\InteractsWithPayload\Facades\AllJobs;

AllJobs::add('user', fn() => auth()->user());

To retrieve the user in your queued job you can call getFromPayload which is available through the InteractsWithPayload trait.

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');
    }  
}

Are you a visual learner?

In this livestream, you'll see our developer Freek explains how you can use the package, it's internals and how we test this package.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

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. We publish all received postcards on our virtual postcard wall.

Installation

This package requires PHP 8.3 or higher and Laravel 13.30 or higher. Applications using older PHP or Laravel versions can continue using the 1.2.x releases.

You can install the package via composer:

composer require spatie/laravel-interacts-with-payload

Usage

To add a value to all jobs call the add method on the AllJobs facade with a name and a closure that returns the value.

use Spatie\InteractsWithPayload\Facades\AllJobs;

AllJobs::add('extraValue', fn() => 'My extra value')

To retrieve the user in your queued job you can call getFromPayload which is available through the InteractsWithPayload trait.

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');
    }  
}

Using models

It is safe to let the closure you pass to add return an Eloquent model.

use Spatie\InteractsWithPayload\Facades\AllJobs;

AllJobs::add('user', fn() => auth()->user())

You can retrieve the model with getFromPayload

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');
    }  
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

This package is inspired by this awesome blogpost by James Brooks. Thank you James for also having helped hunting down that queueing bug in Laravel 👍

License

The MIT License (MIT). Please see License File for more information.

Related Packages

spatie/elasticsearch-search-string-parser

Build Elasticsearch queries based of a query string

24,619 51
spatie/backtrace

A better backtrace

220,267,784 438
spatie/laravel-package-tools

Tools for creating Laravel packages

208,094,001 952
spatie/image-optimizer

Easily optimize images using PHP

100,292,189 2,882
spatie/error-solutions

This is my package error-solutions

92,435,565 67

Version History

Version Released PHP Laravel License
1.3.0 ^8.3 ^13.30 MIT
1.2.2 ^8.2 ^10.0|^11.0|^12.0 MIT
1.2.1 ^8.2 ^10.0|^11.0 MIT
1.2.0 ^8.2 ^10.0|^11.0 MIT
1.1.2 ^8.0 ^8.38|^9.0|^10.0 MIT