0

I have the following in my RedirectifAuthenticated middleware:

public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { return redirect('dashboard'); } return $next($request); } 

But when a user logs in, this is redirecting to /home which I renamed to /dashboard.

I have changed the routes, views etc from home to dashboard.

I have run a search throughout the whole projects and I cannot find a route to /home or a mention of home that is not the title or in unrelated filed such as the yarn.lock file.

I have found many articles on this issue but I do not have an Authenticate.php not do I have the old Auth middleware.

EDIT: Below are my Login Controller and routes:

LoginController:

<?php namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; class LoginController extends Controller { /* |-------------------------------------------------------------------------- | Login Controller |-------------------------------------------------------------------------- | | This controller handles authenticating users for the application and | redirecting them to your home screen. The controller uses a trait | to conveniently provide its functionality to your applications. | */ use AuthenticatesUsers; /** * Where to redirect users after login. * * @var string */ //protected $redirectTo = '/dashboard'; public function authenticated(Request $request) { // Logic that determines where to send the user if($request->user()->hasRole('Stallhollder')){ return redirect('/dashboard'); } if($request->user()->hasRole('Manager')){ return redirect('/dashboard2'); } } /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('guest')->except('logout'); } } 

Routes:

<?php /* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */ Route::get('/', function () { return view('welcome'); }); Auth::routes(); Route::get('/dashboard', 'DashboardController@index'); Route::resource('/bookings', 'BookingsController'); Route::get('/dashboard2', function () { return view('dashboard2'); }); 
5
  • 1
    Can you post your LoginController? And maybe RedirectIfAuthenticated middleware as well Commented Jul 19, 2017 at 13:12
  • @Luke.... Please Post Your Routes Code ... And View File Commented Jul 19, 2017 at 13:27
  • @ka_lin Sorry, got my wires crossed Commented Jul 19, 2017 at 13:35
  • @MatthewDaly: No probs :) happy coding Commented Jul 19, 2017 at 13:43
  • When You Call the dashboard..in url Route::get('/dashboard', 'DashboardController@index'); its go to index page and index page redirect to home page. Commented Jul 19, 2017 at 13:46

2 Answers 2

2

The default Laravel login controller sets the value of $redirectTo to '/home'. You need to update that to the new route as that defines where it gets redirected to after login.

Sign up to request clarification or add additional context in comments.

Comments

0

After Run The php artisan make:auth you have the following controllers.

  • LoginController
  • RegisterController
  • ResetPasswordController.php
  • ForgotPasswordController.php

Now, In Controller File Change The redirect to dashboard

Example: protected $redirectTo = '/dashboard';

Example ( LoginController )

namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; class LoginController extends Controller { use AuthenticatesUsers; protected function authenticated(Request $request) { // Logic that determines where to send the user if($request->user()->hasRole('Stallhollder')){ return redirect('/dashboard'); } if($request->user()->hasRole('Manager')){ return redirect('/dashboard2'); } public function __construct(){ $this->middleware('guest')->except('logout'); } } 

Example ( Routes )

<?php Auth::routes(); // First Line Is `Auth::routes();` Route::get('/dashboard', 'DashboardController@index'); Route::resource('/bookings', 'BookingsController'); Route::get('/dashboard2', function () { return view('dashboard2'); }); ?> 

Example ( RedirectifAuthenticated middleware )

public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { return redirect('/dashboard'); } return $next($request); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.