laravel - How to paginate objects from a relationship -
how can return same query pagination relacted produtos categoria?
my model db:
config model eloquent categoria:
namespace app\models; class categoria extends modeldefault { protected $table = 'categoria'; public function produtos() { return $this->belongstomany('app\models\produto', 'categoria_produto', 'categoria_id')->withtimestamps(); } } config model eloquent produto:
namespace app\models; class produto extends modeldefault { protected $table = 'produto'; public function categorias() { return $this->belongstomany('app\models\categoria', 'categoria_produto', 'produto_id')->withtimestamps(); } public function images() { return $this->hasmany('app\models\produtoimagem','produto_id', 'id'); } } my query produtos categoria:
$produtosporcategoria = categoria::with(['produtos.images.image']) ->where('slug', $categoria_slug) ->ativo() ->first(); dd($produtosporcategoria); here can see printscreen returned array:
if understood need. should try this
$produtosporcategoria = categoria::with(['produtos.images.image']) ->where('slug', $categoria_slug) ->ativo() ->first(); should be
$produtosporcategoria = categoria::with(['produtos.images.image']) ->where('slug', $categoria_slug) ->ativo() ->first(); $produtosporcategoria = $produtosporcategoria->produtos()->paginate(5); 

Comments
Post a Comment