@empty给出"未定义的变量:__ empty_0"

时间:2017-06-28 20:45:46

标签: php laravel laravel-5 blade

我目前正在尝试使用 laravel 5.4 设置我的刀片布局,但在使用它时,我似乎遇到了@empty语句的问题with loops

我尝试使用的代码是:

@foreach ($notifications as $notification)
    <li data-for='{{ $notification->lobbyid }}'>
        @if ($notification->approved == 1) 
             <div class='notification-text'><strong>{{ $notification->sentBy }}</strong> wants access to your lobby:  \"{{$notification->title}}\".</div>
             <div class='notification-actions' id='HI' data-for='{{ $notification->lobbyid }}' data-userid='{{ $notification->userid }}'><span data-type='{ \"as\": \"requesting\", \"action\": 1 }'>Accept</span><span data-type='{ \"as\": \"invited\", \"action\": 0 }'>Deny</span></div> 
        @else 
            <div class='notification-text'><strong>{{ $notification->sentBy }}</strong> invites you to join his lobby: \"{{$notification->title}}\".</div>
            <div class='notification-actions' id='HI' data-for='{{ $notification->lobbyid }}' data-userid='{{ $notification->userid }}'><span data-type='{ \"as\": \"invited\", \"action\": 1 }'>Accept</span><span data-type='{ \"as\": \"invited\", \"action\": 0 }'>Deny</span></div>      
        @endif
     </li>
@empty
    <li>No Notifications</li>
@endforelse

我收到以下错误:

未定义的变量:__ empty_0

单独使用时效果很好:

@endforeach

@empty($notifications)
    <li>No Notifications</li>
@endempty

但我想在laravel文档中使用更清晰的语法。

1 个答案:

答案 0 :(得分:2)

@foreach ($notifications as $notification)

它应该是@forelse而不是@foreach