Support the ongoing development of Laravel.io →
Views Blade Architecture
Last updated 2 years ago.
0

You can use an if statement in blade and check if it is set to hide or show

@if (count($records) === 1)
   I have one record!
@elseif (count($records) > 1)
   I have multiple records!
@else
  I don't have any records!
 @endif
0

Oh, I think you got me wrong.

I don't want to hide it if there are no records but only if a particular action is calling a view.

At the moment I'm doing something like:

View::make('view')->withHideVar(true);

And then in the view:

@if ($hide_var !== true) ....

But I'm unsure if that's the best way.

0

Yes you can pass a variable and check its condition, if it meets (or doesn't meet) the condition then what you put between the if statement will happen.

you could also use

@if (isset(withHideVar)

That way it will just see if that variable has been set and you can send it through only when you need to.

Last updated 9 years ago.
0

Hi, thanks. Yes, I know.

My question is based more on the architectural view whether it's right or wrong to pass a variable to the view in that particular case. Or if there is a better way to make it. It would be nice if the controller wouldn't have to care about hiding things in a view.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

sleepless sleepless Joined 20 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.