/** * Display the specified resource. * * @param $categorySlug * @param $subcategorySlug * @return Response */ public function show($categorySlug, $subcategorySlug) { $category = Category::findBySlugOrFail($categorySlug); $subcategory = $category->subcategories()->where('slug', $subcategorySlug)->first(); if (!$subcategory) { throw new ModelNotFoundException(); } $products = $subcategory->products()->with('reviews')->get(); return view('subcategories.show', compact('category', 'subcategory', 'products')); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('categories')->truncate(); $faker = Faker\Factory::create(); $faker->addProvider(new Faker\Provider\Lorem($faker)); $howMany = 10; //add a category for the main page $main = Category::create(['title' => 'Main page', 'slug' => str_slug('main_page'), 'is_main' => 1]); $parent_ids = []; for ($i = 0; $i < $howMany; $i++) { $title = $faker->sentence(2); $node = Category::create(['title' => $title, 'slug' => str_slug($title), 'is_main' => 0]); // $this->setRandomParent($node, $parent_ids, $faker); //use previous id as parent to speed up setting parent process $node->parent_id = $node->id == 2 || $node->id % 2 == 0 ? null : $node->id - 1; $node->save(); } }
public function getCategories() { $categories = Category::exceptMain()->get(); //convert them to tree return $categories->linkNodes()->toTree(); }
/** * Remove the specified resource from storage. * * @param $categoryId * @param $productId * @return Response */ public function destroy($categoryId, $productId) { $category = Category::findOrFail($categoryId); $product = $category->products()->find($productId); $product->delete(); return redirect()->route('category.products.index', $category->id); }
/** * Remove the specified resource from storage. * * @param $categoryId * @param $productId * @param int $id * @return Response */ public function destroy($categoryId, $productId, $id) { $category = Category::findOrFail($categoryId); $product = Product::findOrFail($productId); $picture = Picture::findOrFail($id); $picture->delete(); return redirect()->route('category.products.pictures.index', [$category->id, $product->id]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $category = Category::findOrFail($id); $category->delete(); return redirect()->route('category.index'); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $mainPageCategory = Category::with('products.reviews', 'products.categories')->mainPage()->first(); return view('pages.index', compact('mainPageCategory')); }