Noting Found

View all related articles

How to Directly Pass The Middleware Instead of Register It in Laravel

Snippets 1 min read

If you have a middleware, and you want to use it in a specific route, you can pass it directly into the route without register it in the kernel file.

1Route::get('posts', PostController::class)->middleware(['auth', CustomMiddleware::class]);

You can do the same on the controller also

1class PostController extends Controller
3 public function __construct()
4 {
5 $this->middleware(['auth', CustomMiddleware::class]);
6 }

Happy Coding!

Related Tags

About the Author

Oussama's Profile Picture
Full Stack Web Developer

I'm a full stack web developer and telecommunications engineer who love to share knowledge and build stuff online!


Join our newsletter

Subscribe to Our Newsletter and never miss our offers, latest news, Articles, etc.

We care about the protection of your data. Read our Privacy Policy.