Can you please write your entire code between 3 backticks so that it's more readable ?
Oct 20, 2022
14
Level 6
redirect to home not work
Sorry, maybe I explained it wrong. We need the user's ID, so if the user is not logged in and clicks on link 1, he will first be directed to the home page and logged in, then come back and click on link 1
Route: this link save product into session and iwe want before save in session redirect us to Page home
Route::get('add-to-cart/{id}', [ProductController::class, 'addToCart'])->name('add.to.cart')->middleware('logined');
kernel.php
'logined' => \App\Http\Middleware\Login::class,
Middleware Login
public function handle(Request $request, Closure $next) {
if (Auth::check()) {
return $next($request);
}
redirect()->route('home');
}
function store product
public function ad(Request $request)
{
$products = $request->session()->get('cart');
$uuid = str()->uuid();
foreach ($products as $product) {
Faktor::create([
'uuid' => $uuid,
'user_id' => Auth::id(),
'product_id' => $product['product_id'],
'name' => $product['name'],
'quantity' => $product['quantity'],
'price' => $product['price'],
]);
}
return redirect()
I hope I have explained correctly
Level 104
@LoverCode I understand the concept, but you don't explain what not working means - what is actually happening when you click the Pay button; are you redirected to the home route; do you sign in; what happens then? Also, where is the Route definition for home, can you show it? Have you reverted to using the logined middleware again?
Please or to participate in this conversation.