How can I write this laravel syntax error?

Source: Internet
Author: User
Use the Registry ticket that comes with laravel5.2 to add a verification code entry to it and submit the Verification Code together with the original form. The controller verification method is as follows: {code ...} because a verification code is added, it becomes like this: 1. A Request $ request parameter is added; 2. A line is added... use the Registry ticket provided by laravel5.2 to add a verification code entry to it and submit the Verification Code together with the original form. The controller verification method is as follows:

protected function validator(array $data){    return Validator::make($data, [        'name' => 'required|max:255',        'email' => 'required|email|max:255|unique:users',        'password' => 'required|confirmed|min:6',            ]);}

This is because a verification code is added:
1. addedRequest $requestParameters;
2. added a line of code.$verification_code_session = $request->session()->get('verification_code', '');)

protected function validator(array $data,Request $request){    $verification_code_session = $request->session()->get('verification_code', '');    return Validator::make($data, [        'name' => 'required|max:255',        'email' => 'required|email|max:255|unique:users',        'password' => 'required|confirmed|min:6',        'verification_code' => 'required|in:' . $verification_code_session    ]);

The error message is as follows:

Type error: Argument 2 passed to App\Http\Controllers\Auth\AuthController::validator() must be an instance of Illuminate\Http\Request, none given, called in D:\wnmp\www\laravel-entrust\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php on line 69

In short, the parameter syntax is incorrect. I don't know how to write the syntax. Let's take a look.

Reply content:

Use the Registry ticket provided by laravel5.2 to add a verification code entry to it and submit the Verification Code together with the original form. The controller verification method is as follows:

protected function validator(array $data){    return Validator::make($data, [        'name' => 'required|max:255',        'email' => 'required|email|max:255|unique:users',        'password' => 'required|confirmed|min:6',            ]);}

This is because a verification code is added:
1. addedRequest $requestParameters;
2. added a line of code.$verification_code_session = $request->session()->get('verification_code', '');)

protected function validator(array $data,Request $request){    $verification_code_session = $request->session()->get('verification_code', '');    return Validator::make($data, [        'name' => 'required|max:255',        'email' => 'required|email|max:255|unique:users',        'password' => 'required|confirmed|min:6',        'verification_code' => 'required|in:' . $verification_code_session    ]);

The error message is as follows:

Type error: Argument 2 passed to App\Http\Controllers\Auth\AuthController::validator() must be an instance of Illuminate\Http\Request, none given, called in D:\wnmp\www\laravel-entrust\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php on line 69

In short, the parameter syntax is incorrect. I don't know how to write the syntax. Let's take a look.

Do not inject the Request class in the form of dependency injection.

Directly

$verification_code_session = Request::session()->get('verification_code', '');

Write on mobile phone, just understand what it means

Besides static callsRequest::session()(Facade) and direct callrequest()->session()(Helper), if you must use dependency injection, you must put the parameters that require dependency injection in front of the brackets, as shown below:

protected function validator(Request $request, array $data){    //...}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.