PHPackages                             datpmwork/laravel-auth-queue - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. datpmwork/laravel-auth-queue

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

datpmwork/laravel-auth-queue
============================

Preserve the authenticated user context when dispatching Laravel queued jobs.

v1.1(11mo ago)0545↑267.9%[3 PRs](https://github.com/datpmwork/laravel-auth-queue/pulls)MITPHPPHP ^7.4|^8.0CI passing

Since Jul 10Pushed 5mo agoCompare

[ Source](https://github.com/datpmwork/laravel-auth-queue)[ Packagist](https://packagist.org/packages/datpmwork/laravel-auth-queue)[ Docs](https://github.com/datpmwork/laravel-auth-queue)[ GitHub Sponsors](https://github.com/datpmwork)[ RSS](/packages/datpmwork-laravel-auth-queue/feed)WikiDiscussions main Synced 3d ago

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

Preserve the authenticated user context when dispatching Laravel queued jobs.
=============================================================================

[](#preserve-the-authenticated-user-context-when-dispatching-laravel-queued-jobs)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5c1a382a58d0e4650e4f072fde988b53d4ca908d0d5db337ff086dfeb79e1785/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646174706d776f726b2f6c61726176656c2d617574682d71756575652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/datpmwork/laravel-auth-queue)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c784d0df1dcd006648f203d8bb69b58d0cfc522d41f5e1cd3f03c29148c4e9fc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646174706d776f726b2f6c61726176656c2d617574682d71756575652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/datpmwork/laravel-auth-queue/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/5d0a72cfe81afccacd6f530a8e999da2c242d961db6c8659f400d78b0dd1d23b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f646174706d776f726b2f6c61726176656c2d617574682d71756575652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/datpmwork/laravel-auth-queue/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/6e83a6559964f82134d16cad26039c150bdde0ce6f7ef76334ce615f5e2d1829/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646174706d776f726b2f6c61726176656c2d617574682d71756575652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/datpmwork/laravel-auth-queue)

This package preserves the authenticated user context when dispatching Laravel queued jobs, notifications, or event listeners.

It allows you to seamlessly access the authenticated user who originally dispatched the job through Laravel's auth() manager when the job is being handled.

This is particularly useful when you need to maintain user context across asynchronous operations.

Requirements
------------

[](#requirements)

- PHP ^7.4 | &gt; 8.0
- Laravel 9.x | 10.x | 11.x | 12.x

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

[](#support-us)

You can support this project via [GitHub Sponsors](https://github.com/sponsors/datpmwork).

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

[](#installation)

You can install the package via composer:

```
composer require datpmwork/laravel-auth-queue
```

Usage
-----

[](#usage)

Add `WasAuthenticated` trait to any `Job`, `Notification`, `Listener` which need to access `auth` data when the Job was dispatched

### Example Job

[](#example-job)

```
class SampleJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, WasAuthenticated;

    public function handle()
    {
        # auth()->user() was the authenticated user who dispatched this job
        logger()->info('Auth ID: '. auth()->id());
    }
}
```

### Example Notification

[](#example-notification)

```
class SampleNotification extends Notification implements ShouldQueue
{
    use Queueable, WasAuthenticated;

    public function via(): array
    {
        return ['database'];
    }

    public function toDatabase(): array
    {
        # auth()->user() was the authenticated user who triggered this notification
        return [auth()->id()];
    }
}
```

### Example Subscriber

[](#example-subscriber)

```
class SampleSubscriber implements ShouldQueue
{
    use Queueable, WasAuthenticated;

    public function subscribe(Dispatcher $dispatcher)
    {
        $dispatcher->listen('eloquent.updated: ' . User::class, [self::class, 'onUserUpdated']);
    }

    public function onUserUpdated(User $user)
    {
        # auth()->user() was the authenticated user who triggered this event
        logger()->info('Auth ID: '. auth()->id());
    }
}
```

Testing
-------

[](#testing)

```
./vendor/bin/pest
```

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [datpmwork](https://github.com/datpmwork)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance62

Regular maintenance activity

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~6 days

Total

3

Last Release

348d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/95dc757b8f49a69b719748c6b5da12eb418732886bba24f833f54f36651399c4?d=identicon)[datpmwork](/maintainers/datpmwork)

---

Top Contributors

[![datpmwork](https://avatars.githubusercontent.com/u/9279315?v=4)](https://github.com/datpmwork "datpmwork (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

laravellaravel-authenticationlaravel-queuelaraveldatpmworklaravel-queueable-auth-context

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/datpmwork-laravel-auth-queue/health.svg)

```
[![Health](https://phpackages.com/badges/datpmwork-laravel-auth-queue/health.svg)](https://phpackages.com/packages/datpmwork-laravel-auth-queue)
```

###  Alternatives

[directorytree/ldaprecord-laravel

LDAP Authentication &amp; Management for Laravel.

5752.3M18](/packages/directorytree-ldaprecord-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6804.7k6](/packages/hasinhayder-tyro)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1563.2k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

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