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
Post a Comment