Laravel - How to do a try / catch in the view?

0

Is there any way to do some try/catch in a view of Laravel 4 ? How could I implement the syntax of blade ?

I would like something like:

@try
<div class="laravel test">
    {{ $usuario->nome }}
</div>
@catch(Exception $e)
    {{ $e->getMessage() }}
@endtry
    
asked by anonymous 14.07.2015 / 17:31

1 answer

2

It is not correct to try / catch in the view. The idea is you always return something to it so you do not have to do this validation.

You can check if the variable has value, if it has it, it displays the value of it, if not, not.

@if $usuario->nome
    {{$usuario->nome}}
@endif

or

{{$usuario->nome or 'Nome não informado'}}
    
16.07.2015 / 14:27