2016-05-02 3 views
0

Je dois montrer une ligne par page. ce mon contoller code de classeComment ajouter Pagination dans 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')); 
} 

ce moi code de classe

@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 

ici, je ne reçois que 1er rang, reste des lignes non visibles .. Je ne sais pas comment ajouter la pagination .

+0

Une seule ligne par page ?? –

+0

Je reçois plus d'une ligne pour $ content..mais j'ai besoin d'afficher une ligne par page. – pinkyrox

Répondre

0

@foreach($content as $content)

Alors tout d'abord changer la dénomination de vars par exemple:

@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() 

Comme vous pouvez le voir, je l'ai ajouté $content->links() après boucle foreach. C'est la méthode de Paginator qui imprime la navigation de pagination.