hal9k
4 months ago
13
11
General

Auth middleware in routes vs in controller

Posted 4 months ago by hal9k

If I use middleware in routes file like this:

Route::group(['middleware' => 'auth'], function() {
    Route::get('/panel', '[email protected]');
});

Do I also have to call it in the constructor:

class PanelController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

Or at one place is (secure) enough?

Please sign in or create an account to participate in this conversation.