D
D
Div-Man2018-08-15 20:45:12
Laravel
Div-Man, 2018-08-15 20:45:12

How to display pivot table records with paginator?

<?php
 
namespace App;
 
use Illuminate\Database\Eloquent\Model;
 
class Category extends Model
{
     public function article()
    {
        return $this->belongsToMany('App\Services\Image');
    }
}

I do this and it works well
$aaa = Category::find(3);
   
dd($aaa->article);

But if you add it with a paginator, then there will be an error
$aaa = Category::find(3)::paginate(2);
   
dd($aaa->article);

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$article

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2018-08-16
@Yadalay

$aaa = Category::find(3);
   
dd($aaa->article()->paginate(2));

J
JhaoDa, 2018-08-15
@JhaoDa

https://laravel.com/docs/5.6/pagination#displaying...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question