2016-02-03 137 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