Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 注册错误,参数1传递给laravel 5.8中的Illumb\Auth\SessionGuard::login()_Php_Laravel - Fatal编程技术网

Php 注册错误,参数1传递给laravel 5.8中的Illumb\Auth\SessionGuard::login()

Php 注册错误,参数1传递给laravel 5.8中的Illumb\Auth\SessionGuard::login(),php,laravel,Php,Laravel,修改我的注册刀片。我添加了两个额外的函数来触发用户注册。我需要的数据正在保存到相应的表中,但我有此错误 传递给Illumb\Auth\SessionGuard::login()的参数1必须 实现接口Illumb\Contracts\Auth\Authenticatable,布尔值 给予,召唤 E:\wamp64\www\aftscredit appzcoder\vendor\laravel\framework\src\illumb\Foundation\Auth\RegistersUsers.p

修改我的注册刀片。我添加了两个额外的函数来触发用户注册。我需要的数据正在保存到相应的表中,但我有此错误

传递给Illumb\Auth\SessionGuard::login()的参数1必须 实现接口Illumb\Contracts\Auth\Authenticatable,布尔值 给予,召唤 E:\wamp64\www\aftscredit appzcoder\vendor\laravel\framework\src\illumb\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'],
        ]);

    }
}

试着打开注册表Users
trait并查看第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如何指示必须返回的
用户的实例。这是关键,因为在trait中完成注册的实际代码假定一个有效的用户模型实例


有时,逐步了解代码并理解Laravel在幕后为您所做的事情是很有帮助的

您没有在create FunctionThank@AlanGe中返回
$user
,我只是添加了“return$user”,但当将我重定向到/email/verify时,页面正在继续重新加载…您的中间件分配一定有问题。我想email/verify的问题是另一个问题。谢谢@AlanGe!你的评论回答了我的问题!谢谢@zoider23!我对原始块的问题是,我不知道如何才能在该结构中获得新注册用户的id,这就是为什么我将user::create放在$user变量中。