- Route::prefix("product")->group(function (){
- Route::get('/', function(){
- $products = Product::all();
- $carts = Transaction::where("user_id", Auth::user()->id)->where("status", 1)->where("type", 2)->get();
- $checkouts = Transaction::where("user_id", Auth::user()->id)->where("status", 1)->where("type", 2)->get();
- $balance = Balance::where("user_id", Auth::user()->id)->first();
- $total_cart = 0;
- $total_checkout = 0;
- foreach($carts as $cart){
- $total_cart += ($cart->product->price * $cart->qty);
- }
- foreach($checkouts as $checkout){
- $total_checkout += ($checkout->product->price * $checkout->qty);
- }
- return view("product.index", [
- "products" => $products,
- "carts" => $carts,
- "checkouts" => $checkouts,
- "total_cart" => $total_cart,
- "total_checkout" => $total_checkout,
- "balance" => $balance
- ]);
[text] cek deh
Viewer
Editor
You can edit this paste and save as new: