/
home
/
sjslayjy
/
public_html
/
theweavenest
/
app
/
Http
/
Controllers
/
Upload File
HOME
<?php namespace App\Http\Controllers; use Razorpay\Api\Api; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\Admin\Product; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Cookie; use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Mail; use App\Models\Details; use App\Models\ExpertForm; use Instamojo\Instamojo; class HomeController extends Controller { public function indexs() { // getData(); // // die(); $product = DB::table('products_attr') ->where('id') ->first(); $categories = DB::table('categories')->get(); $subcatman = DB::table('sub_category') ->join('categories', 'sub_category.Category_Id', '=', 'categories.id') ->where('categories.CategoryName', 'For Men') ->where('sub_category.status', 1) // Corrected: use ->where instead of >where ->select('sub_category.*') ->get(); $subcatwomen = DB::table('sub_category') ->join('categories', 'sub_category.Category_Id', '=', 'categories.id') ->where('categories.CategoryName', 'Women Fashion') ->where('sub_category.status', 1) ->select('sub_category.*') ->get(); $posts = DB::table('posts') -> where ('status',1) ->get(); // Fetch all posts from the posts table // Pass the posts data to the view $home_banner = DB::table('home_banners') ->where('status', 1) ->get(); // Dump and die to inspect the data // dd($home_banner); // Pass the categories data to the view return view('front.index', compact('categories', 'subcatman', 'subcatwomen', 'posts', 'product', 'home_banner')); //dd( $homeCategories); } public function products() { return view('front.product_cat'); } public function gallary() { return view('front.gallary'); } public function blog() { // Fetch all posts from the posts table where status is 1 $posts = DB::table('posts') ->where('status', 1) ->get(); // Pass the $posts variable to the view return view('front.blog', ['posts' => $posts]); } public function showPost($id) { // Retrieve the post with the given ID from the database $post = DB::table('posts')->where('id', $id)->first(); // Assuming your table name is 'posts' if (!$post) { abort(404); // or handle the error in some other way } // Pass the post data to the view using the correct variable name return view('front.blog_cat', compact('post')); } public function showProductsBySubcategory($subcategory_id) { $products = DB::table('products') ->select( 'products.id', 'products.name', 'products.short_desc', 'products.is_promo', 'products.image', DB::raw('MAX(products_attr.price) as attr_price'), DB::raw('MAX(products_attr.mrp) as attr_mrp') ) ->leftJoin('products_attr', 'products.id', '=', 'products_attr.products_id') ->leftJoin('Sub_category', 'Sub_category.id', '=', 'products.sub_category_id') ->leftJoin('categories', 'categories.id', '=', 'Sub_category.category_id') ->where('products.sub_category_id', $subcategory_id) ->groupBy('products.id','products.is_promo','products.short_desc', 'products.name', 'products.image') // Group by all selected columns from products table ->get(); return view('front.product_cat', ['products' => $products]); } public function wshowProductsBySubcategory($subcatwo) { $products = DB::table('products') ->select( 'products.id', 'products.name', 'products.short_desc', 'products.is_promo', 'products.image', DB::raw('MAX(products_attr.price) as attr_price'), DB::raw('MAX(products_attr.mrp) as attr_mrp') ) ->leftJoin('products_attr', 'products.id', '=', 'products_attr.products_id') ->leftJoin('Sub_category', 'Sub_category.id', '=', 'products.sub_category_id') ->leftJoin('categories', 'categories.id', '=', 'Sub_category.category_id') ->where('products.sub_category_id', $subcatwo) ->groupBy('products.id','products.is_promo','products.short_desc', 'products.name', 'products.image') // Group by a ->get(); // print_r($products); // die; return view('front.product_cat', ['products' => $products]); //return view('front.product_cat'); } public function single_product($id) { $result['product'] = DB::table('products')->where('id', $id)->get(); if ($result['product']->isNotEmpty()) { foreach ($result['product'] as $list1) { $result['product_attr'][$list1->id] = DB::table('products_attr') ->leftJoin('sizes', 'sizes.id', '=', 'products_attr.size_id') ->leftJoin('colors', 'colors.id', '=', 'products_attr.color_id') ->where('products_attr.products_id', $list1->id) ->select('products_attr.*', 'sizes.size', 'colors.color') ->get(); } foreach ($result['product'] as $list1) { $result['product_images'][$list1->id] = DB::table('product_images') ->where('product_images.products_id', $list1->id) ->get(); } // Fetch product images $result['product_images'] = DB::table('product_images') ->whereIn('products_id', $result['product']->pluck('id')) ->get(); // Fetch product reviews if available $result['product_review'] = DB::table('product_review') ->leftJoin('customers', 'customers.id', '=', 'product_review.customer_id') ->where('product_review.product_id', $result['product'][0]->id) // Ensure $result['product'] is not empty before accessing index 0 ->where('product_review.status', 1) ->orderBy('product_review.added_on', 'desc') ->select('product_review.rating', 'product_review.review', 'product_review.added_on', 'customers.name') ->get(); } return view('front.single_product', compact('result')); } public function add_to_cart(Request $request) { if($request->session()->has('FRONT_USER_LOGIN')){ $uid=$request->session()->get('FRONT_USER_ID'); $user_type="Reg"; }else{ $uid=getUserTempId(); $user_type="Not-Reg"; } // $size_id=$request->post('size_id'); $color_id=$request->post('color_id'); $pqty=$request->post('pqty'); $product_id=$request->post('product_id'); $result=DB::table('products_attr') ->select('products_attr.id') // ->leftJoin('sizes','sizes.id','=','products_attr.size_id') ->leftJoin('colors','colors.id','=','products_attr.color_id') ->where(['products_id'=>$product_id]) // ->where(['sizes.size'=>$size_id]) ->where(['colors.color'=>$color_id]) ->get(); $product_attr_id=$result[0]->id; $check=DB::table('cart') ->where(['user_id'=>$uid]) ->where(['user_type'=>$user_type]) ->where(['product_id'=>$product_id]) ->where(['product_attr_id'=>$product_attr_id]) ->get(); if(isset($check[0])){ $update_id=$check[0]->id; if($pqty==0){ DB::table('cart') ->where(['id'=>$update_id]) ->delete(); }else{ DB::table('cart') ->where(['id'=>$update_id]) ->update(['qty'=>$pqty]); } }else{ $id=DB::table('cart')->insertGetId([ 'user_id'=>$uid, 'user_type'=>$user_type, 'product_id'=>$product_id, 'product_attr_id'=>$product_attr_id, 'qty'=>$pqty, 'added_on'=>date('Y-m-d h:i:s') ]); $msg=""; } $result=DB::table('cart') ->leftJoin('products','products.id','=','cart.product_id') ->leftJoin('products_attr','products_attr.id','=','cart.product_attr_id') ->leftJoin('sizes','sizes.id','=','products_attr.size_id') ->leftJoin('colors','colors.id','=','products_attr.color_id') ->where(['user_id'=>$uid]) ->where(['user_type'=>$user_type]) ->select('cart.qty','products.name','products.image','sizes.size','colors.color','products_attr.price','products.slug','products.id as pid','products_attr.id as attr_id') ->get(); return response()->json(['msg'=>$msg,'data'=>$result,'totalItem'=>count($result)]); } public function cart(Request $request) { if($request->session()->has('FRONT_USER_LOGIN')){ $uid=$request->session()->get('FRONT_USER_ID'); $user_type="Reg"; }else{ $uid=getUserTempId(); $user_type="Not-Reg"; } $result['list']=DB::table('cart') ->leftJoin('products','products.id','=','cart.product_id') ->leftJoin('products_attr','products_attr.id','=','cart.product_attr_id') ->leftJoin('sizes','sizes.id','=','products_attr.size_id') ->leftJoin('colors','colors.id','=','products_attr.color_id') ->where(['user_id'=>$uid]) ->where(['user_type'=>$user_type]) ->select('cart.qty','products.name','products.image','sizes.size','colors.color','products_attr.price','products.slug','products.id as pid','products_attr.id as attr_id') ->get(); return view('front.cart',$result); } public function registration(Request $request) { if($request->session()->has('FRONT_USER_LOGIN')!=null){ return redirect('/'); } $result=[]; return view('front.registration',$result); } public function registration_process(Request $request) { // Validate the request data $valid = Validator::make($request->all(), [ "name" => 'required', "email" => 'required|email|unique:customers,email', "password" => 'required', "mobile" => 'required|numeric|digits:10', ]); // Check if validation fails if (!$valid->passes()) { return response()->json(['status' => 'error', 'error' => $valid->errors()->toArray()]); } else { // Generate a random ID $rand_id = rand(111111111, 999999999); // Create the customer data array $arr = [ "name" => $request->name, "email" => $request->email, "password" => Crypt::encrypt($request->password), "mobile" => $request->mobile, "status" => 1, "is_verify" => 0, "rand_id" => $rand_id, "created_at" => date('Y-m-d h:i:s'), "updated_at" => date('Y-m-d h:i:s') ]; // Insert the customer data into the database $query = DB::table('customers')->insert($arr); // Check if the query was successful if ($query) { return response()->json(['status' => 'success', 'msg' => "Registration successful."]); } else { return response()->json(['status' => 'error', 'msg' => "Registration failed. Please try again."]); } } } public function login_process(Request $request) { $result=DB::table('customers') ->where(['email'=>$request->str_login_email]) ->get(); if(isset($result[0])){ $db_pwd=Crypt::decrypt($result[0]->password); // $status=$result[0]->status; // $is_verify=$result[0]->is_verify; // if($is_verify==0){ // return response()->json(['status'=>"error",'msg'=>'Please verify your email id']); // } // if($status==0){ // return response()->json(['status'=>"error",'msg'=>'Your account has been deactivated']); // } if($db_pwd==$request->str_login_password){ if($request->rememberme===null){ setcookie('login_email',$request->str_login_email,100); setcookie('login_pwd',$request->str_login_password,100); }else{ setcookie('login_email',$request->str_login_email,time()+60*60*24*100); setcookie('login_pwd',$request->str_login_password,time()+60*60*24*100); } $request->session()->put('FRONT_USER_LOGIN',true); $request->session()->put('FRONT_USER_ID',$result[0]->id); $request->session()->put('FRONT_USER_NAME',$result[0]->name); $status="success"; $msg=""; $getUserTempId=getUserTempId(); DB::table('cart') ->where(['user_id'=>$getUserTempId,'user_type'=>'Not-Reg']) ->update(['user_id'=>$result[0]->id,'user_type'=>'Reg']); }else{ $status="error"; $msg="Please enter valid password"; } }else{ $status="error"; $msg="Please enter valid email id"; } return response()->json(['status'=>$status,'msg'=>$msg]); //$request->password } // public function email_verification(Request $request,$id) // { // $result=DB::table('customers') // ->where(['rand_id'=>$id]) // ->where(['is_verify'=>0]) // ->get(); // if(isset($result[0])){ // DB::table('customers') // ->where(['id'=>$result[0]->id]) // ->update(['is_verify'=>1,'rand_id'=>'']); // return view('front.verification'); // }else{ // return redirect('/'); // } // } // public function forgot_password(Request $request) // { // $result=DB::table('customers') // ->where(['email'=>$request->str_forgot_email]) // ->get(); // $rand_id=rand(111111111,999999999); // if(isset($result[0])){ // DB::table('customers') // ->where(['email'=>$request->str_forgot_email]) // ->update(['is_forgot_password'=>1,'rand_id'=>$rand_id]); // $data=['name'=>$result[0]->name,'rand_id'=>$rand_id]; // $user['to']=$request->str_forgot_email; // Mail::send('front/forgot_email',$data,function($messages) use ($user){ // $messages->to($user['to']); // $messages->subject("Forgot Password"); // }); // return response()->json(['status'=>'success','msg'=>'Please check your email for password']); // }else{ // return response()->json(['status'=>'error','msg'=>'Email id not registered']); // } // } // public function forgot_password_change(Request $request,$id) // { // $result=DB::table('customers') // ->where(['rand_id'=>$id]) // ->where(['is_forgot_password'=>1]) // ->get(); // if(isset($result[0])){ // $request->session()->put('FORGOT_PASSWORD_USER_ID',$result[0]->id); // return view('front.forgot_password_change'); // }else{ // return redirect('/'); // } // } // public function forgot_password_change_process(Request $request) // { // DB::table('customers') // ->where(['id'=>$request->session()->get('FORGOT_PASSWORD_USER_ID')]) // ->update( // [ // 'is_forgot_password'=>0, // 'password'=>Crypt::encrypt($request->password) , // 'rand_id'=>'' // ] // ); // return response()->json(['status'=>'success','msg'=>'Password changed']); // } public function checkout(Request $request) { // $getAddToCartTotalItem = getAddToCartTotalItem(); // dd( $getAddToCartTotalItem); $result['cart_data']=getAddToCartTotalItem(); if(isset($result['cart_data'][0])){ if($request->session()->has('FRONT_USER_LOGIN')){ $uid=$request->session()->get('FRONT_USER_ID'); $customer_info=DB::table('customers') ->where(['id'=> $uid]) ->get(); $result['customers']['name']=$customer_info[0]->name; $result['customers']['email']=$customer_info[0]->email; $result['customers']['mobile']=$customer_info[0]->mobile; $result['customers']['address']=$customer_info[0]->address; $result['customers']['city']=$customer_info[0]->city; $result['customers']['state']=$customer_info[0]->state; $result['customers']['zip']=$customer_info[0]->zip; }else{ $result['customers']['name']=''; $result['customers']['email']=''; $result['customers']['mobile']=''; $result['customers']['address']=''; $result['customers']['city']=''; $result['customers']['state']=''; $result['customers']['zip']=''; } return view('front.checkout',$result ); }else{ return redirect('/'); } } public function apply_coupon_code(Request $request) { $arr=apply_coupon_code($request->coupon_code); $arr=json_decode($arr,true); return response()->json(['status'=>$arr['status'],'msg'=>$arr['msg'],'totalPrice'=>$arr['totalPrice']]); } public function remove_coupon_code(Request $request) { $totalPrice=0; $result=DB::table('coupons') ->where(['code'=>$request->coupon_code]) ->get(); $getAddToCartTotalItem=getAddToCartTotalItem(); $totalPrice=0; foreach($getAddToCartTotalItem as $list){ $totalPrice=$totalPrice+($list->qty*$list->price); } return response()->json(['status'=>'success','msg'=>'Coupon code removed','totalPrice'=>$totalPrice]); } public function login() { return view('front.login'); } public function category(Request $request, $slug) { $sort = $request->input('sort', ''); $sort_txt = ""; $filter_price_start = $request->input('filter_price_start', ''); $filter_price_end = $request->input('filter_price_end', ''); $color_filter = $request->input('color_filter', ''); $colorFilterArr = []; $query = DB::table('products') ->leftJoin('categories', 'categories.id', '=', 'products.category_id') ->leftJoin('products_attr', 'products.id', '=', 'products_attr.products_id') ->leftJoin('sub_category', 'sub_category.id', '=', 'products.sub_category_id') ->where('products.status', 1) ->where('sub_category.Sub_Category_Name', $slug); if ($sort == 'name') { $query->orderBy('products.name', 'asc'); $sort_txt = "Product Name"; } elseif ($sort == 'date') { $query->orderBy('products.id', 'desc'); $sort_txt = "Date"; } elseif ($sort == 'price_desc') { $query->orderBy('products_attr.price', 'desc'); $sort_txt = "Price - DESC"; } elseif ($sort == 'price_asc') { $query->orderBy('products_attr.price', 'asc'); $sort_txt = "Price - ASC"; } if ($request->filled('filter_price_start') && $request->filled('filter_price_end')) { $filter_price_start = $request->input('filter_price_start'); $filter_price_end = $request->input('filter_price_end'); if ($filter_price_start > 0 && $filter_price_end > 0) { $query->whereBetween('products_attr.price', [$filter_price_start, $filter_price_end]); } } if ($request->filled('color_filter')) { $color_filter = $request->input('color_filter'); $colorFilterArr = array_filter(explode(":", $color_filter)); $query->whereIn('products_attr.color_id', $colorFilterArr); } $products = $query->select('products.*')->get(); $product_attr = []; foreach ($products as $product) { $productAttrQuery = DB::table('products_attr') ->leftJoin('sizes', 'sizes.id', '=', 'products_attr.size_id') ->leftJoin('colors', 'colors.id', '=', 'products_attr.color_id') ->where('products_attr.products_id', $product->id) ->get(); $product_attr[$product->id] = $productAttrQuery; } $colors = DB::table('colors')->where('status', 1)->get(); $categories_left = DB::table('categories')->where('status', 1)->get(); $data = [ 'product' => $products, 'product_attr' => $product_attr, 'colors' => $colors, 'categories_left' => $categories_left, 'slug' => $slug, 'sort' => $sort, 'sort_txt' => $sort_txt, 'filter_price_start' => $filter_price_start, 'filter_price_end' => $filter_price_end, 'color_filter' => $color_filter, 'colorFilterArr' => $colorFilterArr, ]; return view('front.category', $data); } public function instamojo_payment_redirect(Request $request) { if ($request->filled(['payment_id', 'payment_status', 'payment_request_id'])) { $payment_status = $request->input('payment_status'); $status = 'Fail'; $redirect_url = '/order_fail'; if ($payment_status == 'Credit') { $status = 'Success'; $redirect_url = '/order_placed'; } DB::table('orders') ->where('txn_id', $request->input('payment_request_id')) ->update([ 'payment_status' => $status, 'payment_id' => $request->input('payment_id') ]); $request->session()->put('ORDER_STATUS', $status); return redirect($redirect_url); } else { return response('Something went wrong', 500); } } // public function instamojo_payment_redirect(Request $request) // { // // Check if the required parameters are present in the request // if ($request->filled(['payment_id', 'payment_status', 'payment_request_id'])) { // // Determine the payment status // $payment_status = $request->input('payment_status'); // // Set the default status and redirect URL // $status = 'Fail'; // $redirect_url = '/order_fail'; // // Check if the payment status is "Credit" // if ($payment_status == 'Credit') { // $status = 'Success'; // $redirect_url = '/order_placed'; // } // // Update the payment status and ID in the orders table // DB::table('orders') // ->where('txn_id', $request->input('payment_request_id')) // ->update([ // 'payment_status' => $status, // 'payment_id' => $request->input('payment_id') // ]); // // Set the ORDER_STATUS session // $request->session()->put('ORDER_STATUS', $status); // // Redirect the user to the appropriate URL // return redirect($redirect_url); // } else { // // Return a 500 error if the required parameters are missing // return response('Something went wrong', 500); // } // } public function order_placed(Request $request) { if($request->session()->has('ORDER_ID')){ return view('front.order_placed'); }else{ return redirect('/'); } } // public function order_fail(Request $request) // { // if($request->session()->has('ORDER_ID')){ // return view('front.order_fail'); // }else{ // return redirect('/'); // } // } public function order_fail(Request $request) { if($request->session()->has('ORDER_ID')){ return view('front.order_fail'); }else{ return redirect('/'); } } public function order(Request $request) { $result['orders']=DB::table('orders') ->select('orders.*','orders_status.orders_status') ->leftJoin('orders_status','orders_status.id','=','orders.order_status') ->where(['orders.customers_id'=>$request->session()->get('FRONT_USER_ID')]) ->get(); return view('front.order',$result); } public function order_detail(Request $request,$id) { $result['orders_details']= DB::table('orders_details') ->select('orders.*','orders_details.price','orders_details.qty','products.name as pname','products_attr.attr_image','sizes.size','colors.color','orders_status.orders_status') ->leftJoin('orders','orders.id','=','orders_details.orders_id') ->leftJoin('products_attr','products_attr.id','=','orders_details.products_attr_id') ->leftJoin('products','products.id','=','products_attr.products_id') ->leftJoin('sizes','sizes.id','=','products_attr.size_id') ->leftJoin('orders_status','orders_status.id','=','orders.order_status') ->leftJoin('colors','colors.id','=','products_attr.color_id') ->where(['orders.id'=>$id]) ->where(['orders.customers_id'=>$request->session()->get('FRONT_USER_ID')]) ->get(); if(!isset($result['orders_details'][0])){ return redirect('/'); } return view('front.order_detail',$result); } public function place_order(Request $request) { try { $rand_id = rand(111111111, 999999999); if ($request->session()->has('FRONT_USER_LOGIN')) { // User is logged in } else { $valid = Validator::make($request->all(), [ "email" => 'required|email|unique:customers,email' ]); if (!$valid->passes()) { return response()->json(['status' => 'error', 'msg' => "The email has already been taken"]); } else { $arr = [ "name" => $request->name, "email" => $request->email, "address" => $request->address, "city" => $request->city, "state" => $request->state, "zip" => $request->zip, "password" => Crypt::encrypt($rand_id), "mobile" => $request->mobile, "status" => 1, "is_verify" => 1, "rand_id" => $rand_id, "created_at" => date('Y-m-d h:i:s'), "updated_at" => date('Y-m-d h:i:s'), "is_forgot_password" => 0 ]; $user_id = DB::table('customers')->insertGetId($arr); $request->session()->put('FRONT_USER_LOGIN', true); $request->session()->put('FRONT_USER_ID', $user_id); $request->session()->put('FRONT_USER_NAME', $request->name); $data = ['name' => $request->name, 'password' => $rand_id]; $user['to'] = $request->email; Mail::send('front/password_send', $data, function ($messages) use ($user) { $messages->to($user['to']); $messages->subject('New Password'); }); $getUserTempId = getUserTempId(); DB::table('cart') ->where(['user_id' => $getUserTempId, 'user_type' => 'Not-Reg']) ->update(['user_id' => $user_id, 'user_type' => 'Reg']); } } // Handle coupon application $coupon_value = 0; if (!empty($request->coupon_code)) { $coupon = apply_coupon_code($request->coupon_code); $coupon = json_decode($coupon, true); if ($coupon['status'] == 'success') { $coupon_value = $coupon['coupon_code_value']; } else { return response()->json(['status' => 'error', 'msg' => $coupon['msg']]); } } $uid = $request->session()->get('FRONT_USER_ID'); $totalPrice = 0; $getAddToCartTotalItem = getAddToCartTotalItem(); foreach ($getAddToCartTotalItem as $list) { $totalPrice += $list->qty * $list->price; } // Ensure total price is not zero if ($totalPrice <= 0) { return response()->json(['status' => 'error', 'msg' => 'Total amount cannot be zero']); } $arr = [ "customers_id" => $uid, "name" => $request->name, "email" => $request->email, "mobile" => $request->mobile, "address" => $request->address, "city" => $request->city, "state" => $request->state, "pincode" => $request->zip, "coupon_code" => $request->coupon_code, "coupon_value" => $coupon_value, "payment_type" => $request->payment_type, "payment_status" => "Pending", "total_amt" => $totalPrice, "order_status" => 1, "added_on" => date('Y-m-d h:i:s') ]; $order_id = DB::table('orders')->insertGetId($arr); if ($order_id > 0) { foreach ($getAddToCartTotalItem as $list) { $productDetailArr = [ 'product_id' => $list->pid, 'products_attr_id' => $list->attr_id, 'price' => $list->price, 'qty' => $list->qty, 'orders_id' => $order_id ]; DB::table('orders_details')->insert($productDetailArr); } $api = new Api(env('key_id'), env('key_secret')); $amount = ($totalPrice - $coupon_value) * 100; if ($amount <= 0) { return response()->json(['status' => 'error', 'msg' => 'Total amount cannot be zero']); } $order = $api->order->create([ 'amount' => $amount, 'currency' => 'INR', 'receipt' => strval($order_id) ]); $txn_id = $order->id; DB::table('orders')->where('id', $order_id)->update(['txn_id' => $txn_id]); DB::table('cart')->where(['user_id' => $uid, 'user_type' => 'Reg'])->delete(); $request->session()->put('ORDER_ID', $order_id); return response()->json(['status' => 'success', 'msg' => 'Order placed successfully', 'amount' => $amount, 'oid' => $txn_id]); } else { return response()->json(['status' => 'error', 'msg' => 'Failed to place order']); } } catch (\Exception $e) { return response()->json(['status' => 'error', 'msg' => $e->getMessage()]); } } public function update_payment_status(Request $request) { //print_r($request->all()); die; try { $order_id = $request->order_id; $payment_id = $request->payment_id; DB::table('orders')->where('txn_id', $order_id)->update([ 'payment_status' => 'Paid', 'payment_id' => $payment_id, ]); return response()->json(['status' => 'success', 'msg' => 'Payment status updated successfully']); } catch (\Exception $e) { return response()->json(['status' => 'error', 'msg' => $e->getMessage()]); } } public function product_review_process(Request $request) { if($request->session()->has('FRONT_USER_LOGIN')){ $uid=$request->session()->get('FRONT_USER_ID'); $arr=[ "rating"=>$request->rating, "review"=>$request->review, "product_id"=>$request->product_id, "status"=>1, "customer_id"=>$uid, "added_on"=>date('Y-m-d h:i:s') ]; $query=DB::table('product_review')->insert($arr); $status="success"; $msg="Thank you for providing your review"; }else{ $status="error"; $msg="Please login to submit your review"; } return response()->json(['status'=>$status,'msg'=>$msg]); } public function search(Request $request, $str) { $products = DB::table('products') ->leftJoin('categories', 'categories.id', '=', 'products.category_id') ->leftJoin('products_attr', 'products.id', '=', 'products_attr.products_id') ->where('products.status', 1) ->where(function ($query) use ($str) { $query->where('products.name', 'like', "%$str%") ->orWhere('products.model', 'like', "%$str%") ->orWhere('products.short_desc', 'like', "%$str%") ->orWhere('products.desc', 'like', "%$str%") ->orWhere('products.keywords', 'like', "%$str%") ->orWhere('products.technical_specification', 'like', "%$str%") ->orWhere('products_attr.color_id', 'like', "%$str%"); }) ->distinct() ->select('products.*') ->get(); $productAttributes = []; foreach ($products as $product) { $attributes = DB::table('products_attr') ->leftJoin('sizes', 'sizes.id', '=', 'products_attr.size_id') ->leftJoin('colors', 'colors.id', '=', 'products_attr.color_id') ->where('products_attr.products_id', $product->id) ->select('products_attr.*', 'sizes.size', 'colors.color') ->get(); $productAttributes[$product->id] = $attributes; } return view('front.search', [ 'products' => $products, 'productAttributes' => $productAttributes, ]); } }