Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use DB;
- use Illuminate\Http\Request;
- use App\Models\Product;
- use App\Models\Category;
- class ShowroomPageController extends Controller
- {
- /**
- * Display a listing of the resource.
- *@param string $slug
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- if (request()->category) {
- $products = Product::with('categories')->whereHas('categories', function ($query) {
- $query->where('slug', request()->category);
- })->take(0)->paginate(9);
- $products = DB::table('products')
- ->select('products.*', 'categories.slug as category_slug')
- ->join('categories', 'categories.id', '=', 'products.category_id')
- ->where('categories.slug', request()->category)
- ->orderBy('products.slug')
- ->take(0)
- ->paginate(9);
- $categories = Category::all();
- } else {
- $products = Product::inRandomOrder()->take(0)->paginate(9);
- $categories = Category::all();
- }
- return view('/pages/showroom')->with([
- 'products' => $products,
- 'categories' => $categories,
- ]);
- }
- /**
- * Display a specified of the resource.
- *
- * @param string $slug
- * @param string $lang
- *
- * @return \Illuminate\Http\Response
- *
- */
- public function show($slug)
- {
- $product = Product::where('products.slug', $slug)
- ->select('products.*', 'categories.slug as category_slug')
- ->addselect('products.*', 'categories.name as category_name')
- ->join('categories', 'categories.id', '=', 'products.category_id')
- ->first();
- $productsLike = DB::table('products')
- ->select('products.*')
- ->join('categories', 'categories.id', '=', 'products.category_id')
- ->where('categories.slug', $product->category_slug)
- ->inRandomOrder()
- ->take(4)
- ->get();
- return view('/pages/product/product')->with([
- 'product'=> $product,
- 'productsLike' => $productsLike,
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment