Reputation: 5799
I am using the below code to redirect to the root page.
return Redirect::to('/');
I have defined the home page route as below.
Route::get('/', 'PagesController@home');
When the page is redirect to root page, I expect the url to be http://localhost/crafts/public/ but its http://localhost/crafts/public/home. I am not sure where does that /home gets added. I have the home function defined in the PagesController file.
This is the PagesController section.
public function home()
{
return view('home');
}
All other routes shown below work fine except the main route.
Route::get('about', 'PagesController@about');
Route::get('contact', 'PagesController@contact');
Route::get('auth/{provider}', 'Auth\AuthController@login');
Route::get('auth/{provider}/callback', 'Auth\AuthController@callback');
Please explain what I am doing wrong?
Upvotes: 1
Views: 286
Reputation: 33309
If you look at
app/http/Middleware/RedirectIfAuthenticated.php
it has this code:
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->check()) {
return redirect('/home');
}
return $next($request);
}
So when you are using Redirect, it probably authenticates first which then calls the handle function above which is clearly adding a /home
I do notice one thing that you said you are using Laravel-5 in the question label. In that case, replace the Redirect code with:
return redirect('/');
The syntax Redirect::To
is for version 4.x or earlier.
Upvotes: 1