⌘K
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
2{
3 public function __construct()
4 {
5 $this->middleware(['auth', CustomMiddleware::class]);
6 }
7}

Happy Coding!

Related Tags

About the Author

Oussama's Profile Picture
Oussama
Full Stack Web Developer | Technical Writer

Oussama is an experienced full-stack web developer with a strong focus on Laravel. He's passionate about crafting web applications with Filament and the TALL Stack. With 8+ years of experience, and he's a dedicated open-source contributor.

Comments

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.