middleware in controller laravel code example

Example 1: laravel create controller

php artisan make:controller MyController

Example 2: create middleware in laravel

php artisan make:middleware nameOfMiddleware

Example 3: how to create controller in laravel

php artisan make:controller PhotoController --resource

Example 4: laravel make middleware

php artisan make:middleware CheckAge

Example 5: laravel controller middleware

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

        $this->middleware('log')->only('index');

        $this->middleware('subscribed')->except('store');
    }
}

Tags:

Misc Example