如何检查当前url是否为laravel blade中的首页?

如何检查当前url是否为laravel blade中的首页?,laravel,if-statement,laravel-blade,Laravel,If Statement,Laravel Blade,我只想在当前url为首页时更改标题标签。 所以我在刀片上写道: @if (\Request::is('/*')) <title>You are on the article page</title> @else <title>You are on the top page</title> @endif 在这种情况下我该怎么办?谢谢。我想您可以使用路线名称 例: @if(@if(request()->route()->getName())==='

我只想在当前url为首页时更改标题标签。 所以我在刀片上写道:

@if (\Request::is('/*'))
<title>You are on the article page</title>
@else
<title>You are on the top page</title>
@endif

在这种情况下我该怎么办?谢谢。

我想您可以使用路线名称

例:

@if(@if(request()->route()->getName())==='top')
你在首页
@否则
你在文章页面上
@恩迪夫

但从代码来看,您似乎使用了查询字符串来显示不同的页面,因此所有(或至少超过1个)页面都将具有相同的URL。因此,您需要将该测试与查询字符串的测试结合起来。你可以:

您可以使用以下内容在视图中访问:

因此,对于标题代码,您可以使用以下内容:

@if (url()->current() === '/' && empty(request()->query('keyword'))
    <title>You are on the top page</title>
@elseif (url()->current() === '/' && request()->query('keyword') === 'something')
    <title>You are on the article page</title>
@endif
@if(url()->current()==='/'&&empty(request()->query('keyword'))
你在首页
@elseif(url()->current()==='/'&&request()->query('keyword')===='something')
你在文章页面上
@恩迪夫

我试过了,但不适合我的情况。我添加了额外的信息。@Tieria两个url是相同的路由。我想你不能这样做,或者你可以检查查询参数来检查页面,比如url有关键工作将是文章页面,否则将是top pageOP没有说明任何关于使用命名路由的内容?我可以用你的建议来完成,Nguyen Hung Thai、 所以我只是从控制器那里得到
$keyword
,然后像
@一样(!empty($keyword))
然后它就工作了。非常感谢!
@if (@if(request()->route()->getName()) === 'top')
<title>You are on the top page</title>
@else
<title>You are on the article page</title>
@endif
url()->current()
$request->query('keyword')
request()->query('keyword')
@if (url()->current() === '/' && empty(request()->query('keyword'))
    <title>You are on the top page</title>
@elseif (url()->current() === '/' && request()->query('keyword') === 'something')
    <title>You are on the article page</title>
@endif