[英]Registration error, Argument 1 passed to Illuminate\Auth\SessionGuard::login() in laravel 5.8
Modify my registration blade. 修改我的注册刀片。 I added 2 additional functions that trigger the registration of the user. 我添加了2个附加功能来触发用户注册。 The data I needed are being saved to the appropriate tables but I am having this error, 我需要的数据已保存到适当的表中,但出现此错误,
Argument 1 passed to Illuminate\\Auth\\SessionGuard::login() must implement interface Illuminate\\Contracts\\Auth\\Authenticatable, boolean given, called in E:\\wamp64\\www\\aftscredit-appzcoder\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Auth\\RegistersUsers.php on line 35 传递给Illuminate \\ Auth \\ SessionGuard :: login()的参数1必须实现接口Illuminate \\ Contracts \\ Auth \\ Authenticatable,给定布尔值,在E:\\ wamp64 \\ www \\ aftscredit-appzcoder \\ vendor \\ laravel \\ framework \\ src \\ Illuminate中调用第35行的\\ Foundation \\ Auth \\ RegistersUsers.php
Here's my Registration controller 这是我的注册控制器
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Referral;
use App\CollectorMember;
use App\HasRoles;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\Request;
class RegisterController extends Controller
{
use RegistersUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest');
}
public function index(Request $request)
{
$referral = '';
$keyword = $request->get('search');
$referral = Referral::where([
['code', $keyword],
['status', 0]
])->first();
if (is_null($keyword))
return view ( 'Auth.register');
elseif ($referral)
return view ( 'Auth.register', compact('referral', $referral))
->withDetails ( $referral )
->withQuery ( $keyword );
else
return view ( 'Auth.register')->withMessage ( 'The code you provided is not EXISTING or not AVAILABLE.' );
}
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
protected function create(array $data)
{
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$user_id = $user->id;
Referral::find($data['referral_id'])->update ([
'status' => 1,
'date_used' => $data['referral_date_used']
]);
return CollectorMember::create ([
'collector_id' => $data['referral_generate_by'],
'borrower_id' => $user_id,
'referral_id' => $data['referral_id'],
]);
}
}
What's causing this? 是什么原因造成的? thanks in advance! 提前致谢!
Try opening the RegistersUsers
trait and look at line 35. A user is not being created. 尝试打开RegistersUsers
特性并查看第35行。没有创建用户。
The original Laravel controller code to create a user is as follows: 创建用户的原始Laravel控制器代码如下:
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
Note how the DocBlock indicates an instance of User
must be returned. 请注意DocBlock如何指示必须返回User
的实例。 This is key because the the actual code that completes the registration, within the trait, assumes aa valid User model instance. 这是关键,因为在特征内完成注册的实际代码假定一个有效的User模型实例。
It's sometimes helpful to step through the code and understand what Laravel is doing for you, behind the scenes. 在幕后逐步浏览代码并了解Laravel为您所做的工作有时会很有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.