#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Applying Middleware to Routes

A middleware class only takes effect once it's actually attached to a route or group of routes. Laravel offers several ways to do this, depending on how broadly the middleware should apply.

Applying Middleware to a Single Route

The most direct approach is chaining the middleware() method onto an individual route definition, listing one or more middleware by their registered name or class.

Applying Middleware to a Group of Routes

When several routes need the same middleware, wrapping them in a Route::middleware([...])->group() call avoids repeating the same call on every single route.

ApproachExample
Single routeRoute::get('/dashboard', ...)->middleware('auth')
Grouped routesRoute::middleware(['auth'])->group(function () {...})
Controller constructor$this->middleware('auth') inside a controller

Stacking Multiple Middleware

Some middleware should run on every single request, while others should only apply to a handful of routes — understanding that distinction is the focus of the next topic.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course