PHPackages                             spatie/laravel-interacts-with-payload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. spatie/laravel-interacts-with-payload

ActiveLibrary[Queues &amp; Workers](/categories/queues)

spatie/laravel-interacts-with-payload
=====================================

Add variables to the payloads of all jobs in a Laravel app

1.2.2(1y ago)6779.4k↓20.3%8MITPHPPHP ^8.2CI passing

Since Apr 15Pushed 8mo ago3 watchersCompare

[ Source](https://github.com/spatie/laravel-interacts-with-payload)[ Packagist](https://packagist.org/packages/spatie/laravel-interacts-with-payload)[ Docs](https://github.com/spatie/laravel_interacts_with_payload)[ GitHub Sponsors](https://github.com/Spatie)[ RSS](/packages/spatie-laravel-interacts-with-payload/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (7)Versions (10)Used By (0)

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

[](#inject-extra-info-to-the-payloads-of-all-jobs-in-a-laravel-app)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8ce400efcbe0043f651f73e2eb04143f6908c8d90898c335d72ed78a8f2a2131/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d696e746572616374732d776974682d7061796c6f61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-interacts-with-payload)[![run-tests](https://github.com/spatie/laravel-interacts-with-payload/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-interacts-with-payload/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/f67e0224eeb3bf2c52180adbf5f6028bda3963cdf8cb8332b846f79032ba2b29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d696e746572616374732d776974682d7061796c6f61642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-interacts-with-payload)

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?
-------------------------

[](#are-you-a-visual-learner)

[In this livestream](https://youtu.be/DY8i5eaXCbM?t=1688), you'll see our developer Freek explains how you can use the package, it's internals and how we test this package.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/6937c2187db6998cf8d5935908077680e1e4fbccec473bd78f25ae22923a8980/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d696e746572616374732d776974682d7061796c6f61642e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-interacts-with-payload)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-interacts-with-payload
```

Usage
-----

[](#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

[](#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
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

This package is inspired by [this awesome blogpost](https://james.brooks.page/blog/injecting-additional-data-into-laravel-queued-jobs/) by [James Brooks](https://twitter.com/jbrooksuk). Thank you James for also having helped hunting down that queueing bug in Laravel 👍

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance53

Moderate activity, may be stable

Popularity44

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 78.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~175 days

Recently: every ~255 days

Total

9

Last Release

458d ago

Major Versions

0.0.1 → 1.0.02021-04-20

PHP version history (2 changes)0.0.1PHP ^8.0

1.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (59 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (6 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (4 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![demianbinsh](https://avatars.githubusercontent.com/u/162578277?v=4)](https://github.com/demianbinsh "demianbinsh (2 commits)")[![joelvh](https://avatars.githubusercontent.com/u/129096?v=4)](https://github.com/joelvh "joelvh (1 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (1 commits)")

---

Tags

spatielaravellaravel\_interacts\_with\_payload

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-interacts-with-payload/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-interacts-with-payload/health.svg)](https://phpackages.com/packages/spatie-laravel-interacts-with-payload)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[spatie/laravel-slack-alerts

Send a message to Slack

3212.6M4](/packages/spatie-laravel-slack-alerts)[spatie/laravel-login-link

Quickly login to your local environment

4381.2M1](/packages/spatie-laravel-login-link)[spatie/laravel-onboard

A Laravel package to help track user onboarding steps

808342.9k1](/packages/spatie-laravel-onboard)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
