Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.4 kB
1
Indexable
Never
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Food;
use App\Models\Cart;


class HomeController extends Controller
{
    public function index(){

        $data = food::all();

        $count=cart::count();

        return view("home", compact("data","count"));

    }

    public function redirects(){
        $data=food::all();
        $usertype = Auth::user()->usertype;
        
        if($usertype=='1'){
            return view('admin.adminhome');
        }

        else{
            return view('home', compact('data'));
        }
    }

    public function addcart(Request $request, $id){
        
        $foodid=$id;
        $quantity=$request->quantity;
        $cart= new cart;

        $cart->food_id=$foodid;
        $cart->quantity=$quantity;
        $cart->save();

        return redirect()->back();

    }

    public function showcart(Request $request){

        $count=cart::count();

        $data2=cart::select('*')->get();

        $data=cart::join('food', 'carts.food_id', '=', 'food.id')->get();

        return view('showcart', compact('count','data', 'data2'));
    }

    public function remove($id){
        $data=cart::find($id);

        $data->delete();

        return redirect()->back();
    }
}
Leave a Comment