Laravel-检查刀片上的路径是否正确
我需要检查2条路线,如果其中一条是真的,请添加一些内容Laravel-检查刀片上的路径是否正确,laravel,routes,laravel-blade,Laravel,Routes,Laravel Blade,我需要检查2条路线,如果其中一条是真的,请添加一些内容 @if (Route::current()->uri() != '/' || Route::current()->uri() != 'login')<div>add some content some contnt </div> @endif 如果我尝试两个路由,它似乎不起作用,您需要使您的条件正确,因为您正在比较url和字符串。 试试这个plz: URL::current() != url('/')
@if (Route::current()->uri() != '/' || Route::current()->uri() != 'login')<div>add some content some contnt </div> @endif
如果我尝试两个路由,它似乎不起作用,您需要使您的条件正确,因为您正在比较url和字符串。 试试这个plz:
URL::current() != url('/')
您需要使您的条件正确,因为您正在比较url和字符串。 试试这个plz:
URL::current() != url('/')
我会在数组中使用路由名称和
在web.php中
Route::get('/', ...)->name('home');
Route::get('/login', ...)->name('login');
然后你可以做这样的事情
in_array(Route::currentRouteName(), ['home', 'login'])
我会在数组中使用路由名称和
在web.php中
Route::get('/', ...)->name('home');
Route::get('/login', ...)->name('login');
然后你可以做这样的事情
in_array(Route::currentRouteName(), ['home', 'login'])
尝试改用路由名称。在web.php文件中输入以下内容:
Route::get('/')->name('home');
Route::get('/login')->name('login');
然后将if条件更改为:
@if (Route::currentRouteName() != 'home' || Route::currentRouteName() != 'login')
<div>add some content some contnt </div>
@endif
@if(Route::currentRouteName()!=“home”| Route::currentRouteName()!=“login”)
添加一些内容
@恩迪夫
尝试改用路由名称。在web.php文件中输入以下内容:
Route::get('/')->name('home');
Route::get('/login')->name('login');
然后将if条件更改为:
@if (Route::currentRouteName() != 'home' || Route::currentRouteName() != 'login')
<div>add some content some contnt </div>
@endif
@if(Route::currentRouteName()!=“home”| Route::currentRouteName()!=“login”)
添加一些内容
@恩迪夫
您可以使用内置方法检查路由名称或模式
请参见Route::is()
或Route::currentRouteName()
例如:
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')或Route::is('login'))..@endif
您可以使用内置方法检查路由名称或模式
请参见Route::is()
或Route::currentRouteName()
例如:
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')或Route::is('login'))..@endif
,您还可以执行以下操作:
request()->routeIs('categories')
或
request()->routeIs(['categories','services')
您还可以执行以下操作:
request()->routeIs('categories')
或
request()->routeIs(['categories','services'])
if语句在我看来很好。应该有用。请注意,您正在检查是否为root或是否为login。当您观察到地址栏不工作时,它显示的URL是什么?if语句在我看来很好。应该有用。请注意,您正在检查是否为root或是否为login。当您观察到地址栏不工作时,地址栏中显示的URL是什么?