简体   繁体   English

如何在Laravel 5.2中检查URL?

[英]How to check url in Laravel 5.2?

I am creating and hiding a certain navigation in Laravel. 我正在Laravel中创建和隐藏某些导航。 The navigation uses nav tag 导航使用导航标签

This is my current code: 这是我当前的代码:

@if (Request::url() === 'login')
    <nav></nav>
@endif

Problem : I only want the tag to appear if it's not in LOGIN page. 问题 :我只希望标签不在“登录”页面时显示。

Please help me fix the code above. 请帮助我修复上面的代码。 Any help is appreciated. 任何帮助表示赞赏。

This should work with your code. 这应该与您的代码一起使用。

! means IS NOT.

@if (!Request::url() === 'login')
    <nav></nav>
@endif

So this code will run when the url isn't 'login'. 因此,该代码将在网址不是“登录”时运行。


You could also use named routes . 您也可以使用named routes ( https://laravel.com/docs/5.2/routing#named-routes ) https://laravel.com/docs/5.2/routing#named-routes

Route::get('login', ['as' => 'login', 'uses' => 'ControllerName@methodName']);

Than you can check if the page is login . 比您可以检查该页面是否已login You can do it like this: 您可以这样做:

@if(Route::is('login'))
    This is the route 'login'
@endif

Hope this works! 希望这有效!

make your login route as follows: 使您的登录路径如下:

Route::get('login', ['as' => 'login', 'uses' => 'ControllerName@methodName']);

Now on view page just do as follows: 现在在查看页面上,只需执行以下操作:

@if(Route::is('login'))
  <nav></nav>
@endif

This will show the 'nav' tag when route is not login Hope this helps you. 当路由未登录时,这将显示“ nav”标签。希望这对您有所帮助。

This should do the trick: 这应该可以解决问题:

the '!' '!' means NOT, so the nav shows when the url is not login. 表示不是,因此导航显示何时未登录该URL。

@if (!Request::is('login')) 
        <nav>I Am a menu item</nav>
@endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM