Php 如何限制Laravel中的通知数量

Php 如何限制Laravel中的通知数量,php,laravel,laravel-5,Php,Laravel,Laravel 5,我尝试了->limit(4)方法,但似乎不起作用 @foreach(auth()->user()->unreadNotifications()->limit(4) as $notification) <li> <a href="profile.html"> <div> {{ $notification->data['message'] }}<span cla

我尝试了
->limit(4)
方法,但似乎不起作用

@foreach(auth()->user()->unreadNotifications()->limit(4) as $notification)
    <li>
        <a href="profile.html">
           <div>
              {{ $notification->data['message'] }}<span class="pull-right text-muted small">{{ time_elapsed_string($notification->created_at) }}</span>
           </div>
        </a>
    </li>
@endforeach
@foreach(auth()->user()->unreadNotifications()->限制(4)为$notification)
  • @endforeach
    您不在此处执行查询:

    @foreach(auth()->user()->unreadNotifications()->take(4)->get() as $notification)
    

    另外,您。

    很难说什么
    未发送的通知
    真正返回,但如果它是集合,您可以使用:

    @foreach(auth()->user()->unreadNotifications()->take(4) as $notification)
    
    @foreach(auth()->user()->unreadNotifications()->take(4)->get() as $notification)
    
    如果是关系,你可以使用:

    @foreach(auth()->user()->unreadNotifications()->take(4) as $notification)
    
    @foreach(auth()->user()->unreadNotifications()->take(4)->get() as $notification)
    
    试试这个

    foreach(\Auth::user()->unreadNotifications->take(1) as $data){echo $data->id;}
    
    同时附加一个
    ->get()
    调用: