datpmwork/laravel-auth-queue 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

datpmwork/laravel-auth-queue

最新稳定版本:v1.1

Composer 安装命令:

composer require datpmwork/laravel-auth-queue

包简介

Preserve the authenticated user context when dispatching Laravel queued jobs.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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

  • PHP ^7.4 | > 8.0
  • Laravel 9.x | 10.x | 11.x | 12.x

Support us

You can support this project via GitHub Sponsors.

Installation

You can install the package via composer:

composer require datpmwork/laravel-auth-queue

Usage

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

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

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

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

./vendor/bin/pest

Changelog

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

Credits

License

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

统计信息

  • 总下载量: 398
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固