I have 2 kind of routes. For Admin, all of my routes are always have an admin prefix. For User, it doesn’t have any prefix at all.
I’m able check if the currect route has admin prefix by using this code:
Route::current()->getPrefix() === '/admin'
But when I tried to do the same for non-prefix (the User) routes, it doesn’t work:
Route::current()->getPrefix() === '/'
How am I supposed to check if the current route doesn’t have prefix? I know I can technically just reverse the logic by using:
Route::current()->getPrefix() !== '/admin'
But I wanted something different so that I don’t get confused easily in the future. Thank you.
2
Answers
As described in my comment, you could extend the Route Facade like follows. This enables you to check the admin prefix like that
CustomRoute::hasPrefix("/admin");
Easiest way might be
There is already simmilar topic:
using Request::is() function with named Routes Laravel