Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

houcem's avatar

Problem with redirectTo

Hi! I am using the predefined RegisterController@create to create 2 different types of users : teachers and students. I would like to redirect to different pages of my website depending on what I am creating :

  • if it's a teacher to the teachers.index
  • if it's a student to the students.index

this is my StudentsController@store

public function store(Request $request)
    {
        $this->validate($request, [
            'firstname' => 'required',
            'lastname' => 'required',
            'email' => 'required',            
            'phone' => 'required',
            'ncin' => 'required'
        ]);

        // create student account
        $data = array(
            'firstname' => $request->input('firstname'),
            'lastname' => $request->input('lastname'),
            'email' => $request->input('email'),
            'ncin' => $request->input('ncin'),
            'phone' => $request->input('phone'),
            'userPrivilege' => $request->input('userPrivilege'),
        );
        $student = new RegisterController();    
        $student->create($data);  

this is my RegisterController@create

protected function create(array $data)
    {
        return User::create([
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'email' => $data['email'],
            'ncin' => $data['ncin'],
            'phone' => $data['phone'],            
            'password' => bcrypt($data['ncin']),
            'userPrivilege' => $data['userPrivilege'],
        ]);        
    }

How should I solve this please?

0 likes
2 replies
houcem's avatar

I think that I should add this method in the RegisterController , am I right? If it's how can I give a custom path to this method? this is what I did:

  • the RegisterController
protected function redirectTo($path)
    {
        return $path;
    }
  • the error

(1/1) ErrorException

Missing argument 1 for App\Http\Controllers\Auth\RegisterController::redirectTo(), called in E:\devserver\laravel\pfeAppV1\vendor\laravel\framework\src\Illuminate\Foundation Auth\RedirectsUsers.php on line 15 and defined

Please or to participate in this conversation.