I am trying to create a new user and it's record in user_info
table, all the database entries are being made but I am seeing this error when I try to route the newly registered user.
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, instance of Illuminate\Http\RedirectResponse given, called in /var/www/myproject/vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php on line 35 and defined
My controller is
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\UserInfo;
use Illuminate\Support\Facades\Auth;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'username' => 'required|max:255|unique:users',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'confirm_email' => 'required|email|max:255|same:email',
'month' => 'required',
'day' => 'required',
'year' => 'required',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
$dateString = $data['year'].'-'.$data['month'].'-'.$data['day'];
$date=date_create($dateString);
$dateString = date_format($date, 'Y-m-d');
// echo $dateString;
$user = User::create([
'username' => $data['username'],
'email' => $data['email'],
'uuid' => $this->getRandomString(),
'password' => bcrypt($data['password']),
'user_type' => 2,
'status' => 'active'
]);
$lastInsertId = $user->id;;
//send mail to user to notify, account has been created
$to = $user->email;
$from = "[email protected]";
$msg = "Welcome! This is free for Mobile, Tablets and Computers. Listen and create the right messge with your music, where ever you are";
$subject = "Welcome to Telatunes";
mail($to, $subject, $msg);
//create record in user info
$userInfo = UserInfo::create([
'user_id' => $user->id,
'address' => '',
'date_of_birth' => $dateString,
'zipcode' => '',
'country_id' => 0,
'state_id' => 0,
'city_id' => 0,
'profile_pic_path' => '',
'gender' => 'male'
]);
return redirect('redirect');
// return User::create([
// 'name' => $data['name'],
// 'email' => $data['email'],
// 'password' => bcrypt($data['password']),
// ]);
}
private function getRandomString($randomStringLength = 15) {
$fullString = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for($i=0; $i<$randomStringLength; $i++) {
$randomIndex = mt_rand(0, 61);
$randomString .= $fullString[$randomIndex];
}
return $randomString;
}
}