How to make paging in a table that this related Laravel 5.4

Asked

Viewed 246 times

1

There is a 2 tables and a pivot where she makes the relationship ManyToMany among the 2 tables.

A table is called Postagems and the other table is called Departamentos, so I’m trying to do a related search by department, when I do the search it takes the data of the departments with the articles of the post table and returns to me, thus getting my search.

Behold:

public function searchDepartamentoGet($id)
{
    $data = array(
        'titulo'        =>  'Artigo Por Departamento',
        'departamento'  =>  Departamento::with('postagems')
                                       ->where('id',  $id)
                                       ->paginate($this->departamento)
    );

    return view('frontend.artigo.departamentos' , $data);
}

So this search returns me this result:

inserir a descrição da imagem aqui

The problem is that my paging only makes the pagination in the variable departamento that I actually want him to make the pagination in the related table postagems where there are 3 articles.

How could I make this pagination?

  • Natan if you have to do the research of Postagems then and make a filter for what I could understand, have as you post the two classes?

  • I found a very quiet way to make pagination with the related tables. See Virgilio 'department' => Department::find($id)->postagems()->paginate($this->department) I have now solved the problem

1 answer

0


Well I found an easier way to make a pagination with related tables. See:

 'departamento'  =>  Departamento::find($id)->postagems()->paginate($this->departamento)

That alone solves the problem.

  • what is $this->departamento????

  • It is a private variable where it contains the number of pages that will appear in the View Ex I want it to appear 10 page in the 1 pagination so I create a private $departamento = 10; ai in the paginate method (I call the pagination Quant I want $this->department). Or you can only make paying(10) that gives in the same

Browser other questions tagged

You are not signed in. Login or sign up in order to post.