Level 75
what i'm doing wrong?
Everything.
1 like
hello i'm trying to do pagination to category page but its errors
web
Route::get('/category/{slug}/{page?}', [WebController::class, 'category'])->name('category');
category model
public function articles()
{
return $this->hasMany(Article::class, 'category_id', 'id')->orderBy('published_at', 'Desc');
}
controller
public function category($slug, $page = 1)
{
$offsetPage = ($page - 1);
$perPage = 24;
$category = AllCategory::bySlug($slug);
$category->articles->skip($perPage * $offsetPage)->take($perPage)->get();
if (!$category) {
abort(404);
}
return view('pages/category')
->with('category', $category);
}
what i'm doing wrong?
Please or to participate in this conversation.