2016-05-02 74 views
0

我需要每頁顯示一行。 此位指示我的類代碼如何在laravel 5中添加分頁

public function showcontent($id) 
{ 
    $story=storybook::find($id); 
    $content=storycontent::where('titleid', $story['id'])->paginate(1); 
    //return $content; 
    return view('storyBook/viewStory',compact('story','content')); 
} 

這個我視圖類代碼

@foreach($content as $content) 
      <?php $a=null; ?> 
      <?php $b=null; ?> 

       <?php $a=$content->file1; ?> 
       <?php $b=$content->file2; ?> 

      <table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px"> 
       <tr> 
        <td style="width: 340px"><img src="/{{$a}}" alt="Mountain View" style="width:330px;height:300px;"></td> 
        <td style="width: 340px"><img src="/{{$b}}" alt="Mountain View" style="width:330px;height:300px;"></td> 
       </tr> 
      </table> 
      <br> 
     @endforeach 

在這裏我只得到1行不可見行的其餘.. 我不知道如何添加分頁。

+0

每頁只有一行? –

+0

我得到多個行$ content ..但我需要顯示每行一行.. – pinkyrox

回答

0

@foreach($content as $content)

所以首先改變瓦爾的命名,例如:

@foreach($content as $entry) 
    <table style="height: 330px;width: 680px;margin-top: 120px;margin-left: 50px"> 
     <tr> 
      <td style="width: 340px"><img src="/{{$entry->file1}}" alt="Mountain View" style="width:330px;height:300px;"></td> 
      <td style="width: 340px"><img src="/{{$entry->file2}}" alt="Mountain View" style="width:330px;height:300px;"></td> 
     </tr> 
    </table> 
    <br> 
@endforeach 

$content->links() 

正如你可以看到我已經foreach循環後添加$content->links()。這是打印出分頁導航的方法Paginator