Ashutosh
Ashutosh

Reputation: 4675

Laravel 5.4 redirect / not working

The command:

php artisan route:list

shows:

GET|HEAD  | /  | App\Http\Controllers\StaticController@index

I added following code in my StaticController controller

public function logout(Request $request)
{
    Auth::logout();
    $request->session()->flush();

    return Redirect::route('/');
}

In my web.php:

Route::get('/', 'StaticController@index');

Route::group(['middleware' => ['web', 'auth']], function () {
    Route::get('/logout', 'MiscController@logout');
});

When I click on logout link, it shows the message:

InvalidArgumentException in UrlGenerator.php line 304:
Route [/] not defined.

When I reload the page showing error, it redirects me to: /login Not able to figure out what's wrong here.

Upvotes: 0

Views: 3112

Answers (1)

Peter Reshetin
Peter Reshetin

Reputation: 925

Replace

return Redirect::route('/');

with

return redirect('/');

Think there is no route with name /

But if you prefer to use route names when redirecting, you may do this:

return redirect()->route('your.route.name', ['id' => $order->id]);

Upvotes: 1

Related Questions