Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Route::current() returns null

I am trying to use the current route in middleware in Laravel 5.7 using the following line of code:

$route = Route::current();

But I get a null value for $route. Any ideas?

like image 426
Farzan Badakhshan Avatar asked Sep 14 '25 01:09

Farzan Badakhshan


1 Answers

The route couldn't be available yet because the router hasn't been yet called. That's depends on what middlewares are called before your middleware.

I think that, in a before middleware, you can try with: $route = $request->path(); just to be sure and not depending on the Router being booted or not.

like image 167
dparoli Avatar answered Sep 16 '25 15:09

dparoli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!