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
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.
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community