Skip to content
Advertisement

Missing required parameters for [Route: login] [URI: {locale}/login] when i redirect as a guest

Whenever I redirect as a guest, I get an error:

Missing required parameters for [Route: login] [URI: {locale}/login].

But it works fine when I logged in. Here are my web.php and HomeController

web.php

Route::get('/', function() {
    return redirect(app()->getLocale());
});

Route::group(['prefix' => '{locale}', 'where' => ['locale' => '[a-zA-Z]{2}'], 'middleware' => 'setlocale'], function () {

Route::get('/', function () {

return view('welcome');
})->name('main');

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

//Customers
Route::get('/customers', 'CustomerController@showcust')->name('customers');
Route::post('/sendcust', 'CustomerController@sendcust')->name('sendcust');


//Items
Route::get('/items', 'ItemController@showitems')->name('items');
Route::post('/senditem', 'ItemController@senditem')->name('senditem');

//Projects
Route::get('/projects', 'ProjectController@showprojects')->name('projects');
Route::post('/sendproj', 'ProjectController@sendproj')->name('sendproj');
//ProjectBillings
Route::get('/projects/{id}/billings', 'ProjectController@showbilling');
Route::post('/projects/{id}', 'ProjectController@addbilling')->name('addbilling');

Route::get('/invoices', 'InvoiceController@showinvoice')->name('invoices');
Route::post('/sendinvoitem', 'InvoiceController@sendinvoitem')->name('sendinvoitem');
Route::get('/invoices/{id}/details', 'InvoiceController@showdetails');
Route::post('/updateitem','InvoiceController@updatedetail')->name('updateitem');
Route::get('invoices/{id}/generate', 'InvoiceController@generate');
Route::post('/updatestatus', 'InvoiceController@changestatus')->name('updatestatus');

});

HomeController.php

public function index()
{
    if(Auth::guest()){
        return redirect(app()->getLocale());
    }

    else{
    return view('admin.home');
    }
}

Advertisement

Answer

The issue is in your AppHttpMiddlewareAuthenticate middleware.

Your login route expects a locale parameter – but when you visit a page that requires authentication as a guest, the Authenticate middleware will be called.

By default, the Authenticate middleware contains:

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

You need to pass the required parameter to the route:

return route('login', ['locale' => $desiredLocale])
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement