Skip to content

v1.0 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6b3cf7a
Preserves authenticated user context
datpmwork Jul 2, 2025
6187b70
Fix styling
datpmwork Jul 2, 2025
715e9a7
Updates support for PHP and Laravel versions
datpmwork Jul 2, 2025
a0571ff
Refactors service provider implementation.
datpmwork Jul 2, 2025
9b9cfce
Merge remote-tracking branch 'origin/1.0' into 1.0
datpmwork Jul 2, 2025
eef68bd
Fix styling
datpmwork Jul 2, 2025
103b13e
Updates development dependencies
datpmwork Jul 2, 2025
fed9a1b
Removes HasRoutes trait from User model.
datpmwork Jul 2, 2025
0179771
Merge remote-tracking branch 'origin/1.0' into 1.0
datpmwork Jul 2, 2025
e3b57e0
Fix styling
datpmwork Jul 2, 2025
720e19f
Updates testbench dependency
datpmwork Jul 2, 2025
94e13d4
Merge remote-tracking branch 'origin/1.0' into 1.0
datpmwork Jul 2, 2025
dd6c9a5
Fix Wrong Trait
datpmwork Jul 2, 2025
01ed22a
Fix styling
datpmwork Jul 2, 2025
580657d
Update Deps
datpmwork Jul 2, 2025
d8c0cde
Merge remote-tracking branch 'origin/1.0' into 1.0
datpmwork Jul 2, 2025
93d9279
Update Deps
datpmwork Jul 2, 2025
c355c7f
Update Deps
datpmwork Jul 2, 2025
4ad6a0e
Update Deps
datpmwork Jul 2, 2025
aadbe41
Removes static analysis tooling
datpmwork Jul 3, 2025
8de925b
Extends compatibility and adds static analysis
datpmwork Jul 3, 2025
804720d
Allow L9
datpmwork Jul 3, 2025
f613851
Update Deps
datpmwork Jul 3, 2025
909e9fd
Update Deps
datpmwork Jul 3, 2025
868c425
Update Desp
datpmwork Jul 3, 2025
9fa8984
Update Deps
datpmwork Jul 3, 2025
9358100
Update Deps
datpmwork Jul 3, 2025
631b914
Update Deps
datpmwork Jul 3, 2025
5de8496
Update Test Case
datpmwork Jul 4, 2025
7dd76bc
Fix styling
datpmwork Jul 4, 2025
d14d138
Ignore Unsued Trait
datpmwork Jul 4, 2025
ef42ea4
Merge remote-tracking branch 'origin/1.0' into 1.0
datpmwork Jul 4, 2025
a89e7a8
Remove some devs packages while testing
datpmwork Jul 7, 2025
851d2d6
Preserves authentication context for queued jobs
datpmwork Jul 8, 2025
93a9667
Fix styling
datpmwork Jul 8, 2025
39ed21b
Fixes auth context in queued jobs
datpmwork Jul 8, 2025
03835d7
Merge remote-tracking branch 'origin/1.0' into 1.0
datpmwork Jul 8, 2025
fa9b2c9
Fix styling
datpmwork Jul 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: :vendor_name
github: datpmwork
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: Ask a question
url: https://github.com/:vendor_slug/:package_name/discussions/new?category=q-a
url: https://github.com/datpmwork/laravel-queueable-auth-context/discussions/new?category=q-a
about: Ask the community for help
- name: Request a feature
url: https://github.com/:vendor_slug/:package_name/discussions/new?category=ideas
url: https://github.com/datpmwork/laravel-queueable-auth-context/discussions/new?category=ideas
about: Share ideas for new features
- name: Report a security issue
url: https://github.com/:vendor_slug/:package_name/security/policy
url: https://github.com/datpmwork/laravel-queueable-auth-context/security/policy
about: Learn how to notify us for sensitive bugs
64 changes: 27 additions & 37 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
name: run-tests
name: Tests

on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
runs-on: ubuntu-latest
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.4, 8.3]
laravel: [12.*, 11.*, 10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 12.*
testbench: 10.*
- laravel: 11.*
testbench: 9.*
php: [8.0, 8.1, 8.2, 8.3]
laravel: [9.*, 10.*, 11.*, 12.*]
stability: [prefer-stable]
exclude:
# Laravel 11 requires PHP 8.2+
- laravel: 10.*
testbench: 8.*

php: 8.0
# Laravel 11 requires PHP 8.2+
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1
# Laravel 12 requires PHP 8.2+
- laravel: 12.*
php: 8.0
- laravel: 12.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}

steps:
- name: Checkout code
Expand All @@ -43,21 +36,18 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite
coverage: none

- name: Setup problem matchers
- name: Remove dev packages for PHP 8.0
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
composer remove larastan/larastan --dev --no-update
composer remove pestphp/pest-plugin-arch --dev --no-update

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: List Installed Dependencies
run: composer show -D

- name: Execute tests
run: vendor/bin/pest --ci
run: vendor/bin/pest
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Changelog

All notable changes to `:package_name` will be documented in this file.
All notable changes to `laravel-queueable-auth-context` will be documented in this file.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) :vendor_name <[email protected]>
Copyright (c) datpmwork <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
122 changes: 68 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,91 +1,105 @@
# :package_description

[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug)
<!--delete-->
---
This repo can be used to scaffold a Laravel package. Follow these steps to get started:

1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton.
2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files.
3. Have fun creating your package.
4. If you need help creating a package, consider picking up our <a href="https://laravelpackage.training">Laravel Package Training</a> video course.
---
<!--/delete-->
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
# Preserve the authenticated user context when dispatching Laravel queued jobs.

## Support us
[![Latest Version on Packagist](https://img.shields.io/packagist/v/datpmwork/laravel-auth-queue.svg?style=flat-square)](https://packagist.org/packages/datpmwork/laravel-auth-queue)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/datpmwork/laravel-auth-queue/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/datpmwork/laravel-auth-queue/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/datpmwork/laravel-auth-queue/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/datpmwork/laravel-auth-queue/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/datpmwork/laravel-auth-queue.svg?style=flat-square)](https://packagist.org/packages/datpmwork/laravel-auth-queue)

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/:package_name.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/:package_name)
This package preserves the authenticated user context when dispatching Laravel queued jobs, notifications, or event
listeners.

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).
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.

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).
This is particularly useful when you need to maintain user context across
asynchronous operations.

## Installation
## Requirements

You can install the package via composer:
- PHP ^7.4 | > 8.0
- Laravel 9.x | 10.x | 11.x | 12.x

```bash
composer require :vendor_slug/:package_slug
```
## Support us

You can publish and run the migrations with:
You can support this project via [GitHub Sponsors](https://github.com/sponsors/datpmwork).

```bash
php artisan vendor:publish --tag=":package_slug-migrations"
php artisan migrate
```
## Installation

You can publish the config file with:
You can install the package via composer:

```bash
php artisan vendor:publish --tag=":package_slug-config"
composer require datpmwork/laravel-auth-queue
```

This is the contents of the published config file:
## Usage

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

### Example Job
```php
return [
];
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());
}
}
```

Optionally, you can publish the views using

```bash
php artisan vendor:publish --tag=":package_slug-views"
### Example Notification
```php
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()];
}
}
```

## Usage

### Example Subscriber
```php
$variable = new VendorName\Skeleton();
echo $variable->echoPhrase('Hello, VendorName!');
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

```bash
composer test
./vendor/bin/pest
```

## Changelog

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

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security Vulnerabilities

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

## Credits

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

## License
Expand Down
57 changes: 25 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
{
"name": ":vendor_slug/:package_slug",
"description": ":package_description",
"name": "datpmwork/laravel-auth-queue",
"description": "Preserve the authenticated user context when dispatching Laravel queued jobs.",
"keywords": [
":vendor_name",
"datpmwork",
"laravel",
":package_slug"
"laravel-queueable-auth-context"
],
"homepage": "https://github.com/:vendor_slug/:package_slug",
"homepage": "https://github.com/datpmwork/laravel-auth-queue",
"license": "MIT",
"authors": [
{
"name": ":author_name",
"email": "[email protected]",
"role": "Developer"
"name": "datpmwork",
"email": "[email protected]",
"role": "Owner"
}
],
"require": {
"php": "^8.4",
"spatie/laravel-package-tools": "^1.16",
"illuminate/contracts": "^10.0||^11.0||^12.0"
"php": "^7.4|^8.0",
"illuminate/support": "^9.0|^10.0|^11.0|^12.0"
},
"require-dev": {
"laravel/pint": "^1.14",
"nunomaduro/collision": "^8.1.1||^7.10.0",
"larastan/larastan": "^2.9||^3.0",
"orchestra/testbench": "^10.0.0||^9.0.0||^8.22.0",
"pestphp/pest": "^3.0",
"pestphp/pest-plugin-arch": "^3.0",
"pestphp/pest-plugin-laravel": "^3.0",
"phpstan/extension-installer": "^1.3||^2.0",
"phpstan/phpstan-deprecation-rules": "^1.1||^2.0",
"phpstan/phpstan-phpunit": "^1.3||^2.0",
"spatie/laravel-ray": "^1.35"
"laravel/pint": "^1.0",
"nunomaduro/collision": "^6.0|^7.0|^8.0",
"larastan/larastan": "^1.0|^2.9|^3.1",
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
"pestphp/pest": "^1.0|^2.0|^3.0",
"pestphp/pest-plugin-laravel": "^1.0|^2.0|^3.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1|^2.0",
"phpstan/phpstan-phpunit": "^1.3|^2.0",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"VendorName\\Skeleton\\": "src/",
"VendorName\\Skeleton\\Database\\Factories\\": "database/factories/"
"DatPM\\LaravelAuthQueue\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"VendorName\\Skeleton\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/"
"DatPM\\LaravelAuthQueue\\Tests\\": "tests/"
}
},
"scripts": {
Expand All @@ -63,13 +59,10 @@
"extra": {
"laravel": {
"providers": [
"VendorName\\Skeleton\\SkeletonServiceProvider"
],
"aliases": {
"Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton"
}
"DatPM\\LaravelAuthQueue\\LaravelAuthQueueServiceProvider"
]
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true
}
6 changes: 6 additions & 0 deletions config/queueable-auth-context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

// config for DatPM/LaravelAuthQueue
return [

];
6 changes: 0 additions & 6 deletions config/skeleton.php

This file was deleted.

Loading