Laravel - How to a try/catch in blade view? -


i create way compile in view, try/catch. how can in laravel?

example:

@try <div class="laravel test">     {{ $user->name }} </div> @catch(exception $e)     {{ $e->getmessage() }} @endtry 

you should not have try/catch blocks in view. view that: representation of data. means should not doing logic (such exception handling). belongs in controller, once you’ve fetched data model(s).

if you’re wanting display default value in case variable undefined, can use or keyword:

{{ $user->name or 'name not set' }} 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -