Laravel FatalThrowableError当我尝试创建新的申请者用户时,在null上调用成员函数create()

时间:2017-08-03 07:13:32

标签: php laravel laravel-5 laravel-5.4

我刚接触laravel 5.4并且我正在尝试创建一个寄存器表单,它将验证并将其存储在申请人表中,并且它表示在null上调用成员函数create()。 继承我的代码:

private $applicantRepository;

    public function repo(ApplicantRepository $applicantRepo)
    {   
        $this->middleware('auth');
        $this->applicantRepository = $applicantRepo;
    }

public function store(CreateApplicantRequest $request)
    {
        $input = $request->all();

        $applicants = $this->applicantRepository->create([
            'name' => $input['name'],
            'email' => $input['email'],
            'password' => bcrypt($input['password']),
            'address' => $input['address'],
            'cellphone_no' => $input['cellphone_no']
        ]);

        Flash::success('Cashier saved successfully.');

        return redirect(route('applicants/home'));
    }

1 个答案:

答案 0 :(得分:1)

我认为如果你想要make构造函数,你应该声明__construct,这样你的repo函数就会变成:

public function __construct(ApplicantRepository $applicantRepo)
    {   
        $this->middleware('auth');
        $this->applicantRepository = $applicantRepo;
    }