1. Home
  2. Laravel
  3. Auth middleware
#laravel#auth

There are a few ways to apply the auth middleware in your project.

// In the Controller constructor
...
    public function __constructor(){
        $this->middleware('auth') // Apply login authorization to all functions
        // or
        $this->middleware('auth')->only(['store', 'update']) // Apply login authorization only to the given functions
        // or
        $this->middleware('auth')->except(['show']) // Apply login authorization to all except the given functions
    }
...

// In the routes file you can apply Auth Middleware to specific routes
Route::get('item', 'ItemsController@index')->middleware('auth');
 
copy
Full Laravel cheatsheet
Sitemap Git repository