Skip to content

Instantly share code, notes, and snippets.

@yooouuri
Created December 9, 2016 08:22
Show Gist options
  • Save yooouuri/e9fd17f1b4b69d63f59cf47127307612 to your computer and use it in GitHub Desktop.
Save yooouuri/e9fd17f1b4b69d63f59cf47127307612 to your computer and use it in GitHub Desktop.
/**
* @param $id
* @param int $page
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function category($id, $page = 1)
{
$maxItems = 9;
$skip = ($page - 1) * $maxItems;
$category = Category::find($id);
$categories = DB::table('categories')
->where('category_id', $id)
->skip($skip)
->take($maxItems)
->get();
$count = DB::table('categories')
->where('category_id', $id)
->count();
return view('category', ['id' => $id, 'category' => $category, 'categories' => $categories, 'page' => $page, 'count' => ceil($count / $maxItems)]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment