Server IP : 162.213.251.212 / Your IP : 18.188.243.41 [ Web Server : LiteSpeed System : Linux business55.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : allssztx ( 535) PHP Version : 8.1.31 Disable Function : NONE Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/self/root/home/allssztx/public_html/easybuyer/app/Http/Controllers/ |
Upload File : |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use App\Models\Banner; use App\Models\Product; use App\Models\ProductCategory; use App\Models\ProductComment; class ShopController extends Controller { // public function index(Request $request) { $data['banner'] = DB::table('banners')->where('banner_id', 2)->first(); // Filter products by category if a category is selected if ($request->has('category') && $request->input('category') != 'all') { $categoryId = $request->input('category'); $query = Product::where('product_status', 1)->where('product_category_id', $categoryId); } else { $query = Product::where('product_status', 1); } // Apply sorting based on selected option if ($request->has('sorting')) { $sorting = $request->input('sorting'); if ($sorting == 'ascending') { $query->orderBy('product_id', 'ASC'); } elseif ($sorting == 'descending') { $query->orderBy('product_id', 'DESC'); } } else { // Default sorting $query->orderBy('product_id', 'ASC'); } $data['products'] = $query->get(); $data['shopbycat'] = ProductCategory::withCount('products') ->where('category_status', 1) ->orderByDesc('category_id') ->limit(11) ->get(); return view('shop', $data); } public function tshirts() { // Products $data['tshirts'] = Product::where('product_category_id', 1)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('tshirts',$data); } public function sweatshirts() { // Products $data['sweatshirts'] = Product::where('product_category_id', 2)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('sweatshirts',$data); } public function hoodies() { // Products $data['hoodies'] = Product::where('product_category_id', 3)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('hoodies',$data); } public function hats() { // Products $data['hats'] = Product::where('product_category_id', 4)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('hats',$data); } public function sweatpants() { // Products $data['sweatpants'] = Product::where('product_category_id', 5)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('sweatpants',$data); } public function shorts() { // Products $data['shorts'] = Product::where('product_category_id', 6)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('shorts',$data); } public function stickers() { // Products $data['stickers'] = Product::where('product_category_id', 7)->where('product_status', 1)->orderBy('product_id', 'ASC')->get(); return view('stickers',$data); } public function product_detail($id) { // Log the product ID \Log::info('Product ID: ' . $id); // Check if product exists $product = Product::find($id); if (!$product) { abort(404, 'Product not found'); } // Banner $data['banner'] = DB::table('banners')->where('banner_id', 7)->first(); $data['products'] = Product::where('product_status', 1)->inRandomOrder()->limit(8)->get(); $data['pro'] = $product; $data['colors'] = DB::select("SELECT c.`color_id`, c.`color_name`, c.`color_code`, c.`color_price`, c.`status`, pc.`product_id` FROM `colors` as c LEFT join `product_colors` pc on pc.color_id = c.color_id WHERE pc.`product_id` = $id"); $data['sizes'] = DB::select("SELECT s.`size_id`, s.`size`, s.`price`, s.`status`, ps.`product_id` FROM `sizes` as s LEFT join `product_sizes` ps on ps.size_id = s.size_id WHERE ps.`product_id` = $id"); $data['other_varient'] = DB::select("SELECT * FROM `other_varients` WHERE `product_id` = $id"); $category = DB::select("SELECT `product_category_id` FROM `products` WHERE `product_id` = $id"); $data['comments'] = ProductComment::where('product_id', $id)->get(); $data['related'] = Product::where('product_id', '!=', $id)->where('product_status', '=', 1)->where('product_category_id', '=', $category[0]->product_category_id)->get(); $data['product'] = $product; return view('product_detail', $data); } public function shop_category($id, Request $request) { $data['banner'] = DB::table('banners')->where('banner_id', 2)->first(); $query = Product::where('product_status', 1)->where('product_category_id', $id); // Apply sorting based on selected option if ($request->has('sorting')) { $sorting = $request->input('sorting'); if ($sorting == 'ascending') { $query->orderBy('product_id', 'ASC'); } elseif ($sorting == 'descending') { $query->orderBy('product_id', 'DESC'); } } else { // Default sorting $query->orderBy('product_id', 'ASC'); } $data['products'] = $query->get(); $data['shopbycat'] = ProductCategory::withCount('products') ->where('category_status', 1) ->orderByDesc('category_id') ->get(); return view('shop', $data); } public function product_list_ajax() { // $products = DB::select("SELECT `product_heading` FROM `products` WHERE `product_status` = 1"); $products = Product::select('product_heading')->where('product_status', '1')->get(); $data = []; foreach($products as $item) { $data[] = $item['product_heading']; } return $data; } public function searchproduct(Request $req) { $searched_pro = $req->search; if($searched_pro != "") { $data['banner'] = DB::table('banners')->where('banner_id',2)->first(); $data['product'] = Product::where("product_front_title","LIKE","%$searched_pro%")->where("product_heading","LIKE","%$searched_pro%")->where('product_status', '=', 1)->get(); return view('search', $data); // if($product) // { // // return redirect('product_detail'.$product->product_id); // $banner = DB::table('banners')->where('banner_id',6)->first(); // return view('search', compact('product','banner')); // } // else // { // return back()->with("status","No Product Matched With Your Search"); // } } else { return redirect()->back(); } } }