adding a cart
This commit is contained in:
+15
-3
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Cart;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Laravel\Fortify\Features;
|
||||
@@ -8,9 +9,20 @@ use Laravel\Fortify\Features;
|
||||
'canRegister' => Features::enabled(Features::registration()),
|
||||
])->name('home');*/
|
||||
|
||||
Route::get('/', fn () => inertia('Home', [
|
||||
'products' => Product::all(),
|
||||
]))->name('home');
|
||||
Route::get('/', function () {
|
||||
$cartId = session('cart_id');
|
||||
$cart = $cartId ? Cart::with('products')->find($cartId) : null;
|
||||
|
||||
return inertia('Home', [
|
||||
'products' => Product::all(),
|
||||
'cart' => $cart
|
||||
? $cart->products->map(fn ($p) => [
|
||||
'product_id' => $p->id,
|
||||
'quantity' => $p->pivot->quantity,
|
||||
])
|
||||
: [],
|
||||
]);
|
||||
})->name('home');
|
||||
|
||||
Route::middleware(['auth', 'verified'])->group(function () {
|
||||
Route::inertia('dashboard', 'Dashboard')->name('dashboard');
|
||||
|
||||
Reference in New Issue
Block a user