修改我的注册刀片。我添加了2个附加功能来触发用户注册。我需要的数据已保存到适当的表中,但出现此错误,
传递给Illuminate \ Auth \ SessionGuard :: login()的参数1必须 实施接口Illuminate \ Contracts \ Auth \ Authenticatable,boolean 给定的 E:\ wamp64 \ www \ aftscredit-appzcoder \ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Auth \ RegistersUsers.php 在第35行
这是我的注册控制人
<?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'],
]);
}
}
是什么原因造成的?预先感谢!
答案 0 :(得分:1)
尝试打开RegistersUsers
特征并查看第35行。未创建用户。
用于创建用户的原始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']),
]);
}
请注意DocBlock如何指示必须返回User
的实例。这很关键,因为在特征中完成注册的实际代码假定一个有效的User模型实例。
有时候,逐步浏览代码并了解Laravel在幕后为您所做的工作有时会很有帮助。