Sunday, February 20, 2022

[FIXED] Laravel 5 Resourceful Routes Plus Middleware

Issue

Is it possible to add middleware to all or some items of a resourceful route?

For example...

<?php

Route::resource('quotes', 'QuotesController');

Furthermore, if possible, I wanted to make all routes aside from index and show use the auth middleware. Or would this be something that needs to be done within the controller?


Solution

In QuotesController constructor you can then use:

$this->middleware('auth', ['except' => ['index','show']]);

Reference: Controller middleware in Laravel 5



Answered By - Marcin NabiaƂek

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.