VaKeR CYBER ARMY
Logo of a company Server : Apache
System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
User : vapecompany ( 2719)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Frontend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Frontend/ShopController.php
<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Product;
use App\Models\Wishlist;
use Carbon\Carbon;
use Gloudemans\Shoppingcart\Facades\Cart;
use Illuminate\Support\Facades\Auth;

class ShopController extends Controller
{
  //   function __construct(){
	// 	$this->middleware('guest:web');
	// }
    public function index()
    {
      // dd(session('cart'));
        $products=Product::paginate(16);
        return view('frontend.pages.shop',['products'=>$products]);
    }

    // function add_cart(Request $request,$id){
    //     $product = Product::where('product_id',$id)->first();
    //    // dd($product);

    //     $cart[$id] = [
    //         "name" => $product->product_name,
    //         "quantity" => 1,
    //         "price" => $product->sale_price,
    //         "image" => $product->product_image
    //     ];
    //     $cart_price=$product->sale_price;
    //     $request->session()->put('cart', $cart);
    //     $request->session()->put('cart_price', $cart_price);
    //     return back();
    //   //  dd($request->session()->all());
    // }

      function add_cart(Request $request,$id){
          $product = Product::where('product_id',$id)->first();
          Cart::add([
              'id' => $request->id,
              'name' => $product -> product_name,
              'qty' => 1,
              'price' => $product -> sale_price,
              'weight' => 1,
              'options' => [
                  'image' => $product->product_image,
              ],
          ]);
          return back()->with('success', 'Product Added To cart');
      }
    function addTocart(Request $request){
        if ($request->ajax()){
          $product = Product::where('product_id',$request->id)->first();
          Cart::add([
              'id' => $request->id,
              'name' => $product -> product_name,
              'qty' => $request -> qty,
              'price' => $product -> sale_price,
              'weight' => 1,
              'options' => [
                  'image' => $product->product_image,
              ],
          ]);
          return response()->json('success');
        }
    }

    // Get wishlist

    function wishlist(){
        $wishlist = Wishlist::with('product')->where('user_id', Auth::id())->get();
        return view('frontend.pages.wishlist', compact('wishlist'));
    }

    // Add wishlist
    function add_wishlist(Request $request,$id){
        if(Auth::check()){

            $exsits = Wishlist::where('user_id', Auth::user()->user_id)->where('product_id', $id)->first();
        
           if(!$exsits){
                Wishlist::insert([
                    'user_id' => Auth::user()->user_id,
                    'product_id' => $id,
                    'created_at' => Carbon::now(),
                ]);
           }else{
                return back()->with('error','This product already in wishlist'); 
           }
            
            return back()->with('success','Product added on wishlist'); 
        }else{
            return back()->with('error','Please Login First'); 
        }
    }
    // Delete wishlist
    function remove_wishlist($id){

        Wishlist::where('user_id', Auth::user()->user_id)->where('id', $id)->first()->delete();
            
        return back()->with('success','Product deleted on wishlist'); 

    }

    public function cart()
    {
       // dd(session('cart')[1]['image']);
       $cart = Cart::content();
       $cartQty = Cart::count();
       $cartTotal = Cart::total();
      return view('frontend.pages.cart', compact('cart','cartQty','cartTotal'));
    }
    // Cart Remove
    public function removeCart(Request $request){
      if ($request->ajax()){
        
        Cart::remove($request->id);
        
        return response()->json('success');
      }
    }
    // Cart Increment
    public function cartIncrement(Request $request){
        if ($request->ajax()){
          
          $row = Cart::get($request->id);
          Cart::update($request->id, $row->qty+1);
          
          return response()->json('success');
        }
    }
    // Cart Increment
    public function cartDecrement(Request $request){
        if ($request->ajax()){
          
          $row = Cart::get($request->id);
          Cart::update($request->id, $row->qty-1);
          
          return response()->json('success');
        }
    }
    public function get_product($id){
        $product=Product::where('product_id',$id)->first();
       // dd($product);
        return view('frontend.pages.product',['product'=>$product]);
    }
}

VaKeR 2022