Hello, can anyone advise me how to do pagination in the model? I have an album with pictures and I would like to see, for example, 20 pictures. Thanks for help
namespace App;
use Illuminate\Database\Eloquent\Model;
class Album extends Model
{
protected $fillable =
[
'title', 'text', 'image'
];
public function images()
{
return $this->hasMany('App\Image')->latest();
}
namespace App\Http\Controllers;
use App\Album;
use App\Http\Controllers\Controller;
class AlbumController extends Controller
{
public function show(Album $album)
{
$images = $album->images()->paginate(20);
return view('album.show', compact('album', 'images'));
}
}