Laravel Undefined属性:LengthAwarePaginator :: $ id

时间:2016-09-19 07:58:26

标签: laravel laravel-5.2

当我尝试将变量作为分页数据传递给视图时出现此错误,我无法找到有关此问题的任何文档

获取数据并传递给查看:

public function index()
{
    return view('tickets')
        ->withData(\App\Tickets::paginate(50));
}

和我的观点:

<table class='table-style' cellpadding='0' cellspacing='0'>
    @foreach ($data as $key=>$contents)
        <tr>
            <td>{{$contents->title}}</td>
            <td>{{$contents->description}}</td>
        </tr>
    @endforeach
</table>
<div style='clear:both;margin-left:12px;'> {!! $data->links() !!}</div>

<div style='clear:both;margin-left:12px;'> {!! $data->render() !!}</div>

Paginate结果:

LengthAwarePaginator {#198 ▼
  #total: 7
  #lastPage: 2
  #items: Collection {#202 ▶}
  #perPage: 5
  #currentPage: 1
  #path: "http://localhost/laravel/public/tickets"
  #query: []
  #fragment: null
  #pageName: "page"
}

1 个答案:

答案 0 :(得分:0)

试试这个

<div style='clear:both;margin-left:12px;'> {{ $data->links() }}</div>

如果它不起作用,请从此

更改您的功能
public function index()
   {
return view('tickets')
    ->withData(\App\Tickets::paginate(50));
   }

public function index(){
    $tickets = DB::table('tickets')->paginate(50);
    return view('tickets', ['tickets' => $tickets]);
   }

并在tickets视图中

<div style='clear:both;margin-left:12px;'> {{ $tickets->links() }}</div>