在Laravel5.2中,如何直接使用Auth包里的方法进行直接注册用户呢?

有些场景下,我不需要使用表单来提交数据进行用户注册,我需要直接在控制器里进行注册,我调用下面的方法。

\Illuminate\Foundation\Auth\RegistersUsers::postRegister($data);

我直接调用这个方法,会提示错误。

Non-static method Illuminate\Foundation\Auth\RegistersUsers::postRegister() should not be called statically, assuming $this from incompatible context
JellyBool

直接执行:

User::create($data);

不行么?

太原微聚科技有限公司

User::create($data); 是可行的,但是传入的password就需要进行hash操作了。我本想直接传入明文的password,然后交由Auth的流程进行注册操作。

Laravel 提供了一个 方法用于验证用户登录

Auth::attempt(['email' => $email, 'password' => $password])

但是没找到资料有没有方法提供注册的。

JellyBool

我看不明白这个是什么意思:

我本想直接传入明文的password,然后交由Auth的流程进行注册操作。

其实用户的注册就是一个保存信息的过程,为啥跟Auth有关。。。

Bantes

Hash::make(‘password’)不行么?注册其实就是把数据进行规则校验后存入数据库啊,和Auth没有啥关系,Auth主要还是进行登陆验证