2016-02-03 93 views
1

当我尝试在验证登录到laravel时推送会话时遇到问题。 我的代码语法如下:尝试登录laravel时推送会话

$valid = DB::table('users') 
         ->select(DB::raw('count(email) as email')) 
         ->where('email' , '=', $request['email']) 
         ->where('password', '=', bcrypt($request['password'])) 
         ->first(); 
     $count = $valid->email; 
     if($count > 1) { 
      $permit = DB::table('users') 
       ->select('permit')->where('email' ,'=', $request['email'])->first(); 
      $permit = $permit->permit; 
      $user_id = DB::table('users') 
       ->select('user_id')->where('email' ,'=', $request['email'])->first(); 
      $user_id = $user_id->user_id; 
      Session::flush(); 
      Session::push('permit', $permit); 
      Session::push('user_id', $user_id); 
     } 

我知道方法bcrypt()不返回相同的字符串另一次,所以我能为问题呢?

回答

0

您可以尝试的方法登录

if(Auth::attempt(['email' =>$request['email'], 'password' => $request['password']])){ 
return view('dashnorad')//login success 

}else{ 

return view('login')//login fiald 
} 

,并在控制器

use Auth; 
+0

工作corecctly访问用户现场像这样

Auth::user()->username 

进口权威性类? – paranoid

+0

我试过了, > 'if(Auth :: attempt($ credentials,$ request-> has('remember'))){ Session :: push(); 返回重定向() - >意向($ this-> redirectPath()) - > withInput() - > with('message','Login successful'); } else if(Auth :: attempt($ credentials)){ Session :: push(); 返回重定向() - >意向($ this-> redirectPath()) - > withInput() - > with('message','Login successful'); } ' 但不工作,.. –

+0

什么错误显示? – paranoid