blade conditional help

Published 1 year ago by madsynn

Can anyone tell me why these will not work? I have tried them all and to no avail. I am trying to only show code if the view is part of the blog.

@if(Request::is() === '/en/resources/blog/')
<h1>this is a blog article</h1>
 @else
    // duh not working
@endif

@if(Request::is() === '/en/resources/blog/')
     @include('frontend.article.partials.temp')
      @else
    // duh not working
@endif


@if(Request::path() == '/en/resources/blog/')
    <h1>article for the blog</h1>
     @else
    // duh not working
@endif

@if(Request::path() === '/en/resources/blog/home-use')
    // code
    @else
    // duh not working
@endif 
Best Answer (As Selected By madsynn)
aivis

Try without the leading slash, en/resources/blog/* not /en/resources/blog/*:

@if(Request::is('en/resources/blog/*'))
    @include('frontend.article.partials.temp')
@else
    // should work
@endif 
aivis
aivis
1 year ago (62,175 XP)

You need to pass the path as an argument to the is method:

@if(Request::is('something'))
  ...
@else
  ...
@endif 

And it seems the path must be without a leading slash - https://laravel.com/docs/5.4/requests#request-path-and-method

madsynn

@aivis thank you in advance.

Ok i tried the following but still nothing.

@if(Request::is('/en/resources/blog/*'))
     @include('frontend.article.partials.temp')
      @else
    // duh not working
@endif 
aivis
aivis
1 year ago (62,175 XP)

Try without the leading slash, en/resources/blog/* not /en/resources/blog/*:

@if(Request::is('en/resources/blog/*'))
    @include('frontend.article.partials.temp')
@else
    // should work
@endif 
madsynn

@aivis That worked thank you!!

Please sign in or create an account to participate in this conversation.