Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 5.5 LengthAwarePaginator在传递到视图后将转换为集合_Php_Laravel_Laravel Blade - Fatal编程技术网

Php Laravel 5.5 LengthAwarePaginator在传递到视图后将转换为集合

Php Laravel 5.5 LengthAwarePaginator在传递到视图后将转换为集合,php,laravel,laravel-blade,Php,Laravel,Laravel Blade,我正在使用LaravelV5.5 我有以下方法 public function AllNotification () { $data[ 'notifications' ] = Notification::ThisUser ()->latest ()->paginate ( 10 ); return view ('Notifications.allNotifications',$data); } 如果idd($data) 这就是结果 当我显示视图并打印{{dd($n

我正在使用LaravelV5.5 我有以下方法

public function AllNotification ()
{
    $data[ 'notifications' ] = Notification::ThisUser ()->latest ()->paginate ( 10 );
    return view ('Notifications.allNotifications',$data);
}
如果i
dd($data)
这就是结果

当我显示视图并打印
{{dd($notifications)}}
这就是显示的内容,
$notifications->links()
因此消失


我不确定在所有其他方法上发生了什么,它工作正常

如果要在视图中对标准的Laravel集合进行分页,可以将此宏代码添加到
boot()函数中的
AppServiceProvider
类中:

    /**
     * Paginate a standard Laravel Collection.
     *
     * @param int $perPage
     * @param int $total
     * @param int $page
     * @param string $pageName
     * @return array
     */
    Collection::macro('paginate', function($perPage, $total = null, $page = null, $pageName = 'page') {
        $page = $page ?: LengthAwarePaginator::resolveCurrentPage($pageName);
        return new LengthAwarePaginator(
            $this->forPage($page, $perPage),
            $total ?: $this->count(),
            $perPage,
            $page,
            [
                'path'     => LengthAwarePaginator::resolveCurrentPath(),
                'pageName' => $pageName
            ]
        );
    });

为什么在单个模型上使用lengthawarepaginator?无法获取要点。单一模型…?奇怪,您是否尝试过不使用
$data
,而是使用
$notifications=Notification::ThisUser…
,并使用
->和('notifications',$notifications)返回视图。应该不会有什么不同,但谁知道我尝试了compact(“通知”),使用相同的行为,我将尝试使用()now@kerbholz,是的,它没有任何区别。由于我正在调用paginate方法,默认情况下不应该发生这种情况吗?是的。如果调用中需要,可以更新默认参数。此外,您还需要使用
slice
功能根据当前页面和页面大小获取正确的数据。