如何在Laravel中验证身份后的会话

时间:2017-07-14 11:25:45

标签: php laravel laravel-5

我试图在Laravel成功登录后将一些值放入会话中,例如name,img,username,last_login等。我尝试使用Auth :: user(),它在回显时从用户详细信息中获取每个细节。

当用户成功登录时,如何立即从不同的表中添加其他参数

我的LoginController.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function username()
    {
        return 'username';
    }

    public function credentials(Request $request)
    {
        return [
            'username' => $request->username,
            'password' => $request->password,
        ];
    }

    protected function authenticated(Request $request, $user)
    {
        if ( !$user->activated ) {
            auth()->logout();

            return back()->withErrors(['email' => 'Your account is not activated yet, please verify your Account.']);
        }

        return redirect()->intended($this->redirectPath());
    }
}

1 个答案:

答案 0 :(得分:0)

一旦您尝试登录,即在用户通过身份验证后,请尝试此

$request->session()->put('auth_user_session_object', Auth::user());