Read Cart Items with JOINS
This commit is contained in:
@ -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')) {
|
||||
|
Reference in New Issue
Block a user