protected $redirectTo = '{name}';
What do you expect this to do?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
why i got an error ?!! In AuthController : protected $redirectTo = '{name}'; In Route file :Route::get('{name}', [ 'uses' =>'User\UserController@getprofile', 'as'=>'user.profile', 'middleware'=>'auth' ]);
protected $redirectTo = '{name}';
What do you expect this to do?
@Snapey i'm trying to use the same one in the route file
You can make:
protected $redirectTo = route('user.profile');
@Thijmen FatalErrorException in AuthController.php line 32: syntax error, unexpected '(', expecting ',' or ';'
@Thijmen PHP does not support property default value to be set this way. You need to initialise them in constructor.
@samer Start looking at method that does the redirection, and override it to handle the dynamic redirect. And by the way
Route::get('{name}', // This route will digest all other routes so change this to something more appropriate.
explain it more
which part?
i made this in AuthController: protected $redirectTo = route('user.profile'); and this :Route::get('{name}', [ 'uses' =>'User\UserController@getprofile', 'as'=>'user.profile', 'middleware'=>'auth' ]); in routes file and i got an error!!
Use a good ide for PHP, you would be able to see the error and the explanation.
FatalErrorException in AuthController.php line 32: syntax error, unexpected '(', expecting ',' or ';'
Google it
ok
@bashy how can i fix this problem ?
@samer You want to redirect to their profile or username on login? Nowhere in this thread have you really said what you want to do.
yeah , i want to redirect users to their profile.
@samer Then you will want to override this method within the AuthController.
I believe the first one will work... intended() with a route() inside...
protected function authenticated($request, $user)
{
// redirect to profile only if they didn't get redirected back from an auth middleware page.
return redirect()->intended(route('user.profile', $user->name));
// redirect to profile regardless of where they wanted to go.
return redirect()->route('user.profile', $user->name);
}
no :(
No what? :|
it didn't work
i'm using laravel 5.2 auth
@samer You provide no information at all. What is your result? Do you see any errors?
FatalErrorException in AuthController.php line 32: syntax error, unexpected '(', expecting ',' or ';'

It would help enormously if you actually read the things we post here.
Try this;
protected $redirectTo = '';
public function __construct() {
$this->redirectTo = route('users.profile');
}
Why bother :( Instead of jumping to coding straight away, read books, go through some tutorials, will make life easy
it work but when i went to account page ErrorException in AuthController.php line 42: Trying to get property of non-object
Look @samer, it would help if you showed us whats on line 42 of AuthController.php...
public function __construct() { $this->middleware($this->guestMiddleware(), ['except' => 'logout']); $this->redirectTo = route('user.profile',Auth::user()->name); //line 42
}
You can't load auth()->user()->name since __construct() is loaded BEFORE you've authed (which is why I suggested overriding the other method that is called upon logging in).
Please or to participate in this conversation.