dimanche 25 décembre 2016

Elegant way for quick IF statement in blade

I´m new to Laravel and I know I can echo variables within double curly brackets like this:

<p></p>

Now in my case I have a form that sometimes contains the variable $posts (which is the table by the way) to update and sometimes doesn´t contain it to insert a row depending on the parameters in the URL.

Of course if there is no post then the part "->id" will fail. Is there an elegant way to make a quick IF statement here, like:

<?php if ($posts) echo $posts["id"]; ?>

but just using the blade engine.

I know I can use @if around the HTML-block but then I would have to write that block twice all the time.

Aucun commentaire:

Enregistrer un commentaire