Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel中注册后自动登录_Php_Laravel - Fatal编程技术网

Php 如何在laravel中注册后自动登录

Php 如何在laravel中注册后自动登录,php,laravel,Php,Laravel,我在laravel中注册用户时遇到一个问题,$user假设为数组,其中包含所有数组元素,同时自动登录以下代码结果false。保存在数据库中的密码是hash::make('password') 有谁能告诉我正确的问题是什么您可以尝试通过他的$user\u id登录用户。因此,您的代码将是: $user_id = $this->user_model->addUser($user); $post = array('password' => $pass_for_auth, 'email

我在laravel中注册用户时遇到一个问题,
$user
假设为数组,其中包含所有数组元素,同时自动登录以下代码结果false。保存在数据库中的密码是
hash::make('password')


有谁能告诉我正确的问题是什么

您可以尝试通过他的
$user\u id
登录用户。因此,您的代码将是:

$user_id = $this->user_model->addUser($user);
$post = array('password' => $pass_for_auth, 'email' => $email);
Auth::loginUsingId($user_id);
您创建了用户,因此它将返回一个用户id,您可以使用该用户id登录该用户

希望这能奏效


更多信息,请访问:

这是进行用户注册的标准方法-您可以创建一个新的用户模型实例并将其传递给Auth::login():


这个身份验证类是什么?你能指定完整的名称空间吗?@RameshPareek不需要它。它有一个别名。只需
使用Auth它。如果确实需要,可以在
config/app.php
别名
键中找到路径,即:
illighte\Support\Facades\Auth
$user_id = $this->user_model->addUser($user);
$post = array('password' => $pass_for_auth, 'email' => $email);
Auth::loginUsingId($user_id);
// do not forget validation!
$this->validate($request, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        ]);

$data = $request->all();

$user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);

Auth::login($user);