skip to Main Content

I have this route in my routes/web.php:

Route::get('/checkout', [CheckoutController::class, 'index'])->name('checkoutIndex')->middleware('auth');

My CheckoutController:

 function index()
{
    if (Cart::instance('default')->count() == 0) {
        return redirect()->route('cartIndex', App::getLocale())->withErrors('Your shopping cart is empty! Please select an item to checkout.');
    }

    $discount = session()->has('coupon') ? session()->get('coupon')['discount'] : 0;

    return view('checkout_index')->with(['lang' => App::getLocale(), 'discount' => $discount]);
}

When I’m not logged in and go to the URL it takes me to a login page as it should. but the login page gives a Missing required parameter for [Route: login] [URI: {lang}/login] [Missing parameter: lang]. error.

The login page works well in its own route anywhere else in the app, I only get the error by clicking on this one specific link:

<a class="btn btn-primary text-light p-3 rounded-0" href="{{ route('checkoutIndex', App::getLocale()) }}">{{__('Proceed to Checkout')}}</a>

I believe having middleware is causing the issue.

I’m using the laravel built-in auth. the route to login is Auth::routes();

Any ideas?

2

Answers


  1. could you try this

    in your AppHttpMiddlewareAuthenticate middleware

    protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }
    
    

    You need to pass the required parameter to the route:

    return route('login', ['lang' => App::getLocale()])
    
    Login or Signup to reply.
  2. change this line:

    <a class="btn btn-primary text-light p-3 rounded-0" href="{{ route('checkoutIndex', App::getLocale()) }}">{{__('Proceed to Checkout')}}</a>
    

    to

    <a class="btn btn-primary text-light p-3 rounded-0" href="{{ route('checkoutIndex', ['lang' => App::getLocale()) ] }}">{{__('Proceed to Checkout')}}</a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search