I found the paginate() method in the Laravel documentation. However, it doesn't work when I implement it. I get an error that paginate does not exist. I know paginate is maybe only for all(), but I need only a few columns, and I need to select the data by region like in the show method. How can I rewrite the index and show methods to get it to work?
Index method
public function index()
{
$tournaments = Tournament::latest()
->get(['title', 'city', 'date_starter_at', 'slug'])->paginate(12);
$regions = Region::all();
}
Show method
public function show(Tournament $tournament)
{
return view('tournaments.show', [ 'tournament' => $tournament,
'regions' => Region::where("id", "=", $tournament->region_id)->get(),
]);
return view('tournaments.index', [
'regions' => $regions,
'tournaments' => $tournaments,
]);
}