2017-02-23 94 views
0

在控制器:如何獲得分頁中laravel 5

function show($feast_id) 
{ 
    $feastMenu = Feast::find($feast_id); 
    $feastMenu->load('images', 'menu', 'users'); 
    $feastMenu->chef->load('chefMeta'); 
    $feastMenu = $feastMenu->toArray(); 
    return view('feasts.showFeastMenu', compact('feastMenu')); 
} 

in views 

@foreach($feastMenu['menu'] as $k => $menu) 

Menu「{{$feastMenu['name']}}」({{count($feastMenu['menu'])}} course meal) 

{{$menu['name']}} 

@foreach($menu['menu_items'] as $item) 

{{$item['name']}} 
    {{$item['description']}} 
@endforeach 

@endforeach 

如何設置分頁到這個請laravel建議我使用laravel 5.我已經使用關係到控制器,並通過這些toArray

+0

你嘗試過什麼嗎?似乎沒有這樣..無論如何,這裏是一個簡單的谷歌搜索:https://laravel.com/docs/5.0/pagination – Condorcho

回答

0

有幾件事我有問題...但首先你應該看看文檔https://laravel.com/docs/5.4/pagination它確實做得很好解釋如何做你想做的事...

無論如何要回答你問我,你ld這樣做...(注意我是如何改變視圖,因爲返回的集合而不是數組)。這也將是您正在使用的引導..如果你不是,你需要查看的文件過來看如何添加分頁鏈接的假設下

控制器:

function show($feast_id) 
{ 
    $feastMenu = Feast::find($feast_id)->simplePaginate(5); 
    $feastMenu->load('images', 'menu', 'users'); 
    $feastMenu->chef->load('chefMeta'); 
    return view('feasts.showFeastMenu', compact('feastMenu')); 
} 

查看:

@foreach($feastMenu->menu as $k => $menu) 

Menu「{{$feastMenu->name}}」({{$feastMenu->menu->count())}} course meal) 

{{$menu->name}} 

@foreach($menu->menu_items as $item) 

{{$item->name}} 
    {{$item->description}} 
@endforeach 

@endforeach 

{{ $feastMenu->links() }}