Ab.net's avatar

Can't use pagination on hasMany relationship...

here is my controller..

namespace App\Http\Controllers\Frontend;

use App\Category; use App\Gallery;

use App\images; use Illuminate\Http\Request; use App\Http\Controllers\Controller;

class GalleryController extends Controller {

public function index(Gallery $gallery,images $image ){
    $galleries=$gallery->with('images')->get();
    $categories=Category::all();


    //to view only the list of galleries created by the user

// $galleries=Gallery::where('created_by', Auth::user()->id)->get(); return view('frontend.gallery',compact('galleries','paginate','categories'));

}

}

here is my model

namespace App;

use Illuminate\Database\Eloquent\Model;

class Gallery extends Model {

protected $table='gallery';

protected $fillable=['name','category_id'];

public function images(){

    return $this->hasMany('App\images');
}
public function category(){

    return $this->belongsTo('App\Category');
}

}

how can i paginate all images in the gallery...

0 likes
3 replies
coder_uzb's avatar

use paginate() method instead get() method. for example: $galleries=$gallery->with('images')->paginate(10);

Ab.net's avatar

i know that but it only paginates the gallery data not the images..

Please or to participate in this conversation.