Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - check if routes on blade

I need to check 2 routes, and if one is true, add some content

@if (Route::current()->uri() != '/' || Route::current()->uri() != 'login')<div>add some content some contnt </div> @endif

I have tried with '||' and 'OR' and 'or'. I have also tried with Request::path(), which works only when checking 1 route

@if (Route::current()->uri() != '/') <div>add some content some contnt </div> @endif

If I try 2 routes it doesn't seem to work

like image 557
José Neves Avatar asked Nov 30 '22 21:11

José Neves


1 Answers

You can use the built in methods to check for a route name or pattern.

See Route::is() or Route::currentRouteNamed()

For example:

Route::get('users', 'Controller..')->name('users.index');
Route::get('users/{id}', 'Controller..')->name('users.show');

Assuming you are in the following path : users/1

@if(Route::is('users.show') )
    // true
@endif

@if(Route::is('users') )
    // false
@endif

@if(Route::is('users.*') )
    // true
@endif

So in your example try @if(Route::is('home') or Route::is('login'))..@endif

like image 111
Raja Khoury Avatar answered Dec 06 '22 00:12

Raja Khoury