Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ShaunL's avatar

Blade if statement

Hi All,

I'm attempting to compile the following in a partial to a blade template without much success, appears if I add an || (OR) conditional into the if statement it will not work correctly, am I missing something? There was not an example of multiple conditionals in the documentation so many i'm doing something that isn't supported?

@if(Request::path() != '/' || Request::path() != 'another/url')
...some code
@endif

Thanks

0 likes
6 replies
ShaunL's avatar

@sukonovs what suggestions would you have for this situation? I'm trying to show certain buttons in a partial depending on the url the user is on. Would it be better to just build separate partials then?

Thanks

sukonovs's avatar
Level 6

In Controller:

$isSomeCondition = Request::path() != '/'  || Request::path() != 'another/url'; // import request or use global namespace with \ 

Then pass variable to the view...

In view:

@if($isSomeCondition)
 // do the stuff
@endif

First of all you extracted app logic form tempalte, and in template condition is more descriptive. If controller is full of logic you can extract this to separate Class or make a global function... but it is a good first step.

thomaskim's avatar

@ShaunL What's the error you are getting? An || (OR) conditional should work inside blade if conditionals.

The problem I see with the current example is that the if conditional will always return true.

phildawson's avatar

Best to put that logic in a view composer rather than in controllers to avoid copy and paste wherever the partial is used.

http://laravel.com/docs/5.1/views#view-composers

The problem I see with the current example is that the if conditional will always return true.

^ This.

!(Request::is('/')  || Request::is('another/url'))
ShaunL's avatar

@phildawson @thomaskim @sukonovs thank you all for your help! I'll extract the logic to the controller, I might also explore view composer but not sure if I'll need it since this should be a fairly basic thing.

Please or to participate in this conversation.