Laravel 5.6注册后重定向位置修改无效问题求助
Hey there, let's figure out why your registration redirect isn't behaving even after updating the $redirectTo value in RegisterController.php. Since your login redirect works fine, we can focus on registration-specific logic and common gotchas:
1. Check for Overridden Methods in RegisterController
Laravel's auth controllers prioritize custom methods over the $redirectTo property. Double-check if your RegisterController has any of these methods that might be hardcoding /home:
// Look for this method protected function redirectPath() { return '/home'; // Update this to '/dashboard' if present } // Or the registered() method, which runs after successful registration protected function registered(Request $request, $user) { return redirect('/home'); // Change this to '/dashboard' }
If either exists, updating the return value should fix the redirect.
2. Clear All Caches
Cached routes or configs can hold onto old redirect values. Run these commands in your terminal:
php artisan route:clear php artisan config:clear php artisan view:clear composer dump-autoload
This ensures your latest changes are loaded instead of cached data.
3. Verify Auth Route Definitions
Make sure you haven't modified the default auth routes in web.php to override the registration flow. The standard line should be:
Auth::routes();
If you've replaced this with custom registration routes, ensure the controller and redirect logic points to /dashboard.
4. Check Middleware for Unexpected Redirects
Look into any global middleware or auth-specific middleware (like auth or guest) that might be forcing a redirect to /home. For example, if you modified the RedirectIfAuthenticated middleware, ensure it redirects authenticated users to /dashboard instead of /home.
5. Test in Incognito Mode
Sometimes browser caching can cause old redirects to persist. Try registering a new user in an incognito/private window to rule out client-side caching issues.
6. Add Debug Logs to Confirm the Redirect Value
Add a quick log statement to your RegisterController to confirm what $redirectTo is actually set to:
public function __construct() { $this->middleware('guest'); \Log::info('Registration redirect target: ' . $this->redirectTo); }
Check your storage/logs/laravel.log file after attempting a registration—this will tell you if the value is correctly set to /dashboard or if something is overriding it.
7. Check Custom Request Classes
If you're using a custom RegistrationRequest class (instead of the default Illuminate\Foundation\Http\FormRequest), ensure it doesn't have any redirect logic that's pointing to /home.
内容的提问来源于stack exchange,提问作者Rashed Hasan

