Laravel身份验证登录不起作用 [英] Laravel auth login not working

查看:300
本文介绍了Laravel身份验证登录不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是laravel的新手,我正在使用Laravel身份验证系统,虽然可以注册,但是登录没有任何作用.

I am new to laravel, I'm working on a Laravel authentication system, and while registration works, but login doesn't do anything.

class UserController extends Controller
{

    public function postSignUp(Request $request)
    {


        $email = $request['email'];
        $first_name = $request['first_name'];
        $password = bcrypt($request['password']);

        $user = new User;

        $user->email = $request->email;
        $user->first_name = $request->first_name;
        $user->password = bcrypt($request->password);

        $user->save();

        Auth::login($user);

        return redirect()->route('hotelier.index')->with('alert-success','Data has been saved successfully');


    }


    public function postSignIn(Request $request)
    {

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

            return redirect()->route('hotelier.index');

        }

         return redirect()->back();

    }

}

Route(web.php)

    Route::group(['middleware' => ['web']], function (){

        Route::get('/', function () {
            return view('welcome');
        });

        Route::resource('hotelier','HotelierController');

            Route::post('/signup', [

            'uses'=> 'UserController@postSignUp',
            'as' =>'signup'

        ]);


        Route::post('/signin', [

            'uses'=> 'UserController@postSignIn',
            'as' =>'signin'

        ]);


    } );

   Auth::routes();

   Route::get('/home', 'HomeController@index')->name('home');

请让我知道我如何登录

谢谢

推荐答案

可能为时已晚,但可能会对其他人有所帮助. 您是否注意到扩展了Illuminate\Foundation\Auth\User as AuthenticatableUser模型内部的protected $fillable = [...]?确保设置用户模型的所有属性,这些属性已在protected $fillable = [...]中定义,然后尝试使用Auth::login($user);登录 我的用户模型看起来像 命名空间App \ Models;

May be its too late but might help others. Have you noticed protected $fillable = [...] inside your User model that extends Illuminate\Foundation\Auth\User as Authenticatable ? Make sure you setting all the properties for the User Model those have been defined in protected $fillable = [...] and then try to login using Auth::login($user); My User model looks like namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable {

    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    // Make sure you set these properties for the model
    protected $fillable = ['name', 'username', 'email', 'password', 'contact',];
.
.
.
}

这篇关于Laravel身份验证登录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆