In some scenarios, I do not need to use the table forms submit data for user registration, I need to register directly in the controller, I call the following method.
\Illuminate\Foundation\Auth\RegistersUsers::postRegister($data);
I call this method directly, will prompt the error.
Non-static method Illuminate\Foundation\Auth\RegistersUsers::postRegister() should not be called statically, assuming $this from incompatible context
Actually, what I want to know is. Laravel provides a way to verify that a user is logged on
Auth::attempt(['email' => $email, 'password' => $password])
Is there a similar method for me to register as a member directly after I have passed in the user information?
Reply content:
In some scenarios, I do not need to use the table forms submit data for user registration, I need to register directly in the controller, I call the following method.
\Illuminate\Foundation\Auth\RegistersUsers::postRegister($data);
I call this method directly, will prompt the error.
Non-static method Illuminate\Foundation\Auth\RegistersUsers::postRegister() should not be called statically, assuming $this from incompatible context
Actually, what I want to know is. Laravel provides a way to verify that a user is logged on
Auth::attempt(['email' => $email, 'password' => $password])
Is there a similar method for me to register as a member directly after I have passed in the user information?
First of all, the object you call the method is not a class, it is an attribute (trait) and cannot be called directly to see the source code.
Second, the method you are calling is not a static method (static) and cannot be called (::).
Finally, Laravel is the user registration by the controller Authcontroller generated by the PHP artisan Make:auth command, and the following is a method for registering users from the controller.
(ty0716 's simple answer also tells you that registering a user in a controller is a way to save user information to a database, so you might think more.) In addition, data validation validation needs to be done yourself. )
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]); }
Laravel 5.2 In the make:auth generated is a common method, the specific needs to adjust according to their own circumstances. In general, it cannot be used directly because the database structure is different. Suggest writing your own method.
User::create(array( 'name' => 'your name', 'username' => 'your_username', 'email' => 'name@domain.io', 'password' => Hash::make('your_password'),));
Add Route::auth () before the route that requires login;
You see
Route::auth();
文件路径 vendor/laravel/framework/src/Illuminate/Routing/Router.php 第346行
It is not necessary to specify the login in routes.php, the registered route