我需要检查 2 条路线,如果有一条路线,则添加一些内容
@if (Route::current()->uri() != '/' || Route::current()->uri() != 'login')<div>add some content some contnt </div> @endif
我试过'||'和“或”和“或”。我也试过
Request::path()
, 仅在检查 1 条路线时有效@if (Route::current()->uri() != '/') <div>add some content some contnt </div> @endif
如果我尝试 2 条路线,它似乎不起作用
最佳答案
您可以使用内置方法来检查路由名称或模式。
见 Route::is()
或 Route::currentRouteNamed()
例如:
Route::get('users', 'Controller..')->name('users.index');
Route::get('users/{id}', 'Controller..')->name('users.show');
假设您在以下路径中:users/1
@if(Route::is('users.show') )
// true
@endif
@if(Route::is('users') )
// false
@endif
@if(Route::is('users.*') )
// true
@endif
所以在你的例子中尝试 @if(Route::is('home') or Route::is('login'))..@endif
关于Laravel - 检查 Blade 上的路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60047963/