How can I pass multiple routes as arguments to the Route::is() method in Laravel 8?
Asked Answered
F

2

5

I am working on a Laravel 8 application. I need to use Route::is for multiple routes, like this

@if(Route::is('user') or Route::is('register') or Route::is('login'))
    Do something
@endif

The goal

I want to shorten this syntax so I tried to pass the routes as arguments to the Route::is() method:

@if(Route::is('user,register,login'))
    Do something
@endif

The problem

The above method does not work.

Is there an alternative, working way to pass multiple routes as arguments?
Feliciafeliciano answered 28/3, 2022 at 11:19 Comment(0)
P
7

You can do that as shown below

@if(request()->routeIs(['user','register','login']))
   Do something
@endif
Platy answered 28/3, 2022 at 11:31 Comment(0)
M
1

Even easier way:

@if(request()->routeIs('user','register','login'))
   Do something
@endif
Mycostatin answered 11/8, 2023 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.