Skipp
Skipp

Reputation: 43

Blade concatenate variables with default value

Is there a way to make something like this work?

{{ $user->name .' '. $user->last_name or '---' }}

Setting it up with @if-then isn't "elegant" as most of the laravel stuff is :)

Upvotes: 4

Views: 9127

Answers (1)

noodles_ftw
noodles_ftw

Reputation: 1313

Check if $user->name and $user->last_name are not empty first, then determine what value you want to show with a shorthand if/else statement:

{{ ($user->name && $user->last_name) ? $user->name .' '. $user->last_name : '---' }}

Upvotes: 6

Related Questions