I believe that the solution presented and marked as accepted will generate a lot of unnecessary code if you want to do this in several lines.
Instead, why not use the operator ?:
PHP? I believe that in addition to improving the understanding of the code, you will have less work.
Instead of doing like this:
{{ ($produto->complemento != '') ? $produto->complemento : 'Este produto não tem complemento' }}
It’s easier to do that:
{{ $produto->complemento ?: 'Este produto não tem complemento' }}
If you need to use the trim
, you can do so too:
{{ trim($produto->complemento) ?: 'Este produto não tem complemento' }}
See an example, using PHP
, in the IDEONE
Consider taking a look at my answer. I think it’s a way that makes things easier
– Wallace Maxters