Please tell me what kind of function validator is in RegisterController. I read the documentation from here and the question, judging by it, there are a lot of ways to validate the data, for example, inject the Request parameter into the function and work with it. And here, moreover, some incomprehensible function is nowhere described, not redefined, it is also not clear where this miracle is called. But without this function, registration does not work. What is happening in general? ... It seems to me or is yii2 intuitive in this respect. I just started to go to Lara, before that I worked with phalcon and yii2 ... So for now, as you see, there are difficulties in understanding the general concept of Lara ...

<?php namespace App\Http\Controllers\Auth; use App\User; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; class RegisterController extends Controller { /* |-------------------------------------------------------------------------- | Register Controller |-------------------------------------------------------------------------- | | This controller handles the registration of new users as well as their | validation and creation. By default this controller uses a trait to | provide this functionality without requiring any additional code. | */ use RegistersUsers; /** * Where to redirect users after registration. * * @var string */ protected $redirectTo = '/home'; /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('guest'); } /** * Get a validator for an incoming registration request. * * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ 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:6|confirmed', ]); } /** * 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']), ]); } } 
  • Before drawing conclusions, you need to look at the class that is inherited in the class treits. In this case, on the RegistersUsers . - Alexxosipov
  • Hmm, I was definitely not attentive. But still, it would be better if they carried it out to the interface and implemented it in the controller so it would be clearer. Maybe. Thanks anyway;) - John Browning

1 answer 1

so also it is not clear where this miracle is called

Called here: /vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php ( use RegistersUsers; in the above code snippet), in the register method that processes the request with user data when trying to register.

  • And the registered function which is in the same box, need to be registered? Or how? - John Browning
  • @JohnBrowning, yes, judging by the fact that the function is empty - you can override it in the code of your controller - Artem Korsunov