Skip to content
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

[11.x] middleware support for specific method in resource routes #53313

Open
wants to merge 5 commits into
base: 11.x
Choose a base branch
from

Conversation

MrPunyapal
Copy link
Contributor

@MrPunyapal MrPunyapal commented Oct 26, 2024

Enhancement: Middleware Assignment for Resource & Singleton Routes

This pull request enables assigning middleware to specific resourceful methods on resource and singleton routes within the Laravel framework. Key changes include new method 'middlewareFor` for method-specific middleware assignment and updates to resource registration logic to support these configurations.

Examples after merging:

Route::resource('users', UserController::class)->middlewareFor('show', 'auth');
Route::apiResource('users', UserController::class)->middlewareFor(['show', 'update'], 'auth');
Route::resource('users', UserController::class)
    ->middlewareFor('show', 'auth')
    ->middlewareFor('update', 'auth');
Route::apiResource('users', UserController::class)
    ->middlewareFor(['show', 'update'], ['auth', 'verified']);

Route::singleton('users', UserController::class)->middlewareFor('show', 'auth');
Route::apiSingleton('users', UserController::class)->middlewareFor(['show', 'update'], 'auth');
Route::singleton('users', UserController::class)
    ->middlewareFor('show', 'auth')
    ->middlewareFor('update', 'auth');
Route::apiSingleton('users', UserController::class)
    ->middlewareFor(['show', 'update'], ['auth', 'verified']);

I'm up for withoutMiddlewareFor if it's in demand.

… set middleware for specific methods on registered resource
…ability to set middleware for specific methods on registered resource
…t for setting middleware for specific methods on registered resources
@MrPunyapal MrPunyapal changed the title [WIP] [11.x] middleware support for specific method in resource routes [11.x] middleware support for specific method in resource routes Oct 26, 2024
@aniket-magadum
Copy link

Looks good to have 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants