diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 698df09..3b533f1 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -3,6 +3,9 @@ namespace App\Http\Controllers; use App\Models\User; + +use Illuminate\Support\Facades\DB; + use App\Models\Cart; use App\Models\Products; use Illuminate\Http\Request; @@ -31,35 +34,7 @@ class MainController extends Controller return view('register'); } - // public function registerUser(Request $data) - // { - // // Validate the input data - // $data->validate([ - // 'name' => 'required|string|max:255', - // 'email' => 'required|string|email|max:255|unique:users', - // 'password' => 'required|string|min:8|confirmed', - // 'file' => 'required|file|mimes:jpg,png,jpeg|max:2048', - // ]); - // // Check if the email already exists - // if (User::where('email', $data->input('email'))->exists()) { - // return redirect('register')->with('error', 'Email already exists!'); - // } - - // // Create a new user - // $newUser = new User(); - // $newUser->name = $data->input('name'); - // $newUser->email = $data->input('email'); - // $newUser->password = Hash::make($data->input('password')); // Hashing the password - // $newUser->picture = $data->file('file')->getClientOriginalName(); - // $data->file('file')->move('uploads/profiles/', $newUser->picture); - // $newUser->type = "Customer"; - // if ($newUser->save()) { - // return redirect('login')->with('success', 'Account created successfully!'); - // } - - // return view('register')->with('error', 'Account creation failed. Please try again.'); - // } public function registerUser(Request $data) { @@ -139,6 +114,37 @@ class MainController extends Controller return view('blogDetails'); } + // public function cart() + // { + // $cartItems = DB::table('products') + // ->join('carts', 'carts.productsId', 'product.id') + // ->select('products.name', 'products.price', 'products.picture', 'products.quantity as pQuantity', 'carts.*') + // ->where('carts.customerId', session()->get('id')) + // ->get(); + + // dd($cartItems); + + // return view('cart', compact('cartItems')); + // } + + public function cart() + { + $cartItems = DB::table('products') + ->join('carts', 'carts.productId', '=', 'products.id') + ->select('products.name', 'products.price', 'products.picture', 'products.quantity as pQuantity', 'carts.*') + ->where('carts.customerId', session()->get('id')) + ->get(); + + //dd($cartItems); + + return view('cart', compact('cartItems')); + } + + + + + + public function addToCart(Request $data) { if (session()->has('id')) { diff --git a/database/migrations/2024_07_04_080725_create_carts_table.php b/database/migrations/2024_07_04_080725_create_carts_table.php index 834a010..5efc504 100644 --- a/database/migrations/2024_07_04_080725_create_carts_table.php +++ b/database/migrations/2024_07_04_080725_create_carts_table.php @@ -13,9 +13,9 @@ return new class extends Migration { Schema::create('carts', function (Blueprint $table) { $table->id(); - $table->integer('productId')->default(0); - $table->integer('customerId')->default(0); - $table->integer('quantity')->default(0); + $table->integer('productId')->nullable(); + $table->integer('customerId')->nullable(); + $table->integer('quantity')->nullable(); $table->timestamps(); }); diff --git a/public/css/style.css b/public/css/style.css index b6f44db..e758eb3 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -2329,12 +2329,20 @@ ol { } .shopping__cart__table table tbody tr td.product__cart__item { - width: 400px; + width: 300px; } .shopping__cart__table table tbody tr td.product__cart__item .product__cart__item__pic { float: left; margin-right: 30px; + /* height: 260px; */ + + /* float: left; + margin-right: 30px; + height: 260px; + width: 100%; + object-fit: contain; + object-position: center; */ } .shopping__cart__table table tbody tr td.product__cart__item .product__cart__item__text { diff --git a/resources/views/cart.blade.php b/resources/views/cart.blade.php index edb5214..a297639 100644 --- a/resources/views/cart.blade.php +++ b/resources/views/cart.blade.php @@ -8,8 +8,8 @@
@@ -34,88 +34,63 @@