0
votes

I am creating website for a school and i am using laravel built in authentication to register new users, but i want add a field in the registration form for scratch card pin so it checks the pin table whether the pin is used or not.My problem is if create function inside authcontroller cant return a view.

So i got this error message

ErrorException in Guard.php line 430:

Argument 1 passed to Illuminate\Auth\Guard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Http\RedirectResponse given

here is my authcontroller

 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return User
 */


protected function create(array $data)
{

    $spin=$data['pin'];
    $pins = Pin::where('pin', $spin)
           ->get();

    if(  $pins[0]->status == 0)
    {      

    Pin::where('pin', $spin)
      ->update(['status' => 1]);  

      return User::create([
        'name' => $data['name'],
        'username' => $data['username'],
        'email' => $data['email'],
        'password' => bcrypt($data['password']),
    ]);

    }

    else{

    return redirect()->back();



    }   

This is my registration form

1
maybe consider marking the answer as accepted? - Gaz_Edge

1 Answers

0
votes

The reason is that you are incorrectly modifying the protected create() method. See how the return response must always be User from the documented comments? You on the other hand, are sometimes returning a redirect response - hence the error message you are getting.

There is likely to be some laravel class somewhere trying to authenticate the user using the create() method. When it receives a RedirectResponse instance instead, it throws an error as it was expecting an instance of User

Don't return anything but User in the create() method