Redirect To Create Method Of RegisterController In Laravel

- 1 answer

I Wanted to redirect to create method of registerController in laravel after a particular action.

So that the user can login after the registration is complete

the screenshoot of the Corresponding error



Assuming you are using the default RegisterController provided by Laravel.

create is a protected method, so you cannot use it as an action in a Route; you may only use public methods there.

The public methods that are meant as route actions in the default implementation are:

  • showRegistrationForm
  • register (this one calls create internally)

So either redirect him to the Route that has showRegistrationForm as action - the user may then fill out the form, submit it, and is registered.

Or programmatically create the user in your particular action using User::create(). You can even use the returned/created User object to programmatically login the user in the current session using Auth::login():

// Creates the record in the database. $newUser returned by the create method is the created User object.
$newUser = \App\User::create([
    'email' => '[email protected]',
    'password' => bcrypt('thepasswordforthenewuser'),
// Pass to the SessionGuard to log him in.