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',];
.
.
.
}