public function categories() { $view = Input::get('view'); if ($view == null) { return redirect('/admin/categories?view=hierarchy'); } $levels = ['Main Category', 'Subcategory', 'Post Sub Category']; $types = ['main-categories', 'sub-categories', 'post-sub-categories']; $views = ['Hierarchy', 'Type', 'All']; $cats = Category::roots()->get(); $category = Input::get('category'); $_category = Category::find($category); if ($view == 'type') { $type = Input::get('type'); if ($type == null) { $type = $types[0]; } // array_keys() = get keys from value // appends() = add 'get' variables (to url) $cats = Category::whereDepth(array_keys($types, $type))->paginate(25)->appends(Input::except('page')); } else { if ($view == 'all') { $cats = Category::paginate(25)->appends(Input::except('page')); } } return view('admin.main')->with('category', $_category)->with('cats', $cats)->with('levels', $levels)->with('view', $view)->with('views', $views)->with('types', $types); // only for 'type' view }
public function getSubCatSet() { $catarray = []; $cats = Category::whereDepth(1)->get(); $counter = 0; for ($col = 0; $col < 3; $col++) { $fillmore = true; $row = 0; $colarray = []; while ($fillmore) { if (isset($cats[$counter])) { $colarray[$row] = ['id' => $cats[$counter]->id, 'name' => $cats[$counter]->name]; } else { break; } $row++; $counter++; if ($row > 11) { $fillmore = false; } } $catarray[$col] = $colarray; } return $catarray; }
public function __construct() { // $productQuery = Globex::with('images')->select('id', 'title', 'description', 'price', DB::raw('0 as type')); // $adQuery = Advertisement::with('images')->select('id', 'title', 'description','price', DB::raw('1 as type')); // $motorQuery = Motor::with('images')->select('id', 'title', 'description','price', DB::raw('2 as type')); // $this->products = $adQuery->get()->merge($productQuery->get())->merge($motorQuery->get()); $this->products = Product::with('producible')->get(); $this->emirates = Emirate::all(); $this->cats = Category::whereDepth(0)->get(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $data = ['myads' => Auth::customer()->get()->advertisements, 'cats' => Category::whereDepth(2)->lists('name', 'id')]; return view('pages.myads', $data); }
public function getSubCats() { return Category::whereDepth(1)->get(); }