Check if variable exist in laravel's blade directive

前端 未结 13 1431
清歌不尽
清歌不尽 2021-02-03 19:23

I\'m trying to create blade directive which echo variable (if variable defined) or echo \"no data\" if variable undefined.

This is my code in AppServiceProvider.ph

相关标签:
13条回答
  • 2021-02-03 19:50

    The best and cleanest way check if a variable exists in blade:

     {!! !empty($myvariable) ? $myvariable : 'variable does not exist' !!}
    
    0 讨论(0)
提交回复
热议问题