2016-01-07 64 views
0

我有點困惑的代碼。在laravel 5中有多個auth Attemp()的問題

auth::attempt()不適合我,任何人都可以幫助我嗎?

Controller.php這樣

public function postLogin(Request $request) 
{ 
    .... 
    if (\Auth::attempt('frontendUsers', $userdata)) { 
     return Redirect::back()->with('success',true); 
    } else { 
     return redirect('login'); 
    } 
} 

view.blade.php

<form name="myForm1" id="loginform" role="form" method="post" action="{{ action('Auth\[email protected]') }}"> 
    <input type="text" placeholder="Card No" name="cardno"/> 
    <input type="password" placeholder="Password" name="password"/> 
    <div class="col-lg-6 col-xs-3 clear-both height"> 
     <label class="remember">Remember Me:</label> 
     <input type="checkbox" class="remember-check"/> 
    </div> 
    <div class="login-submit"> 
     <input type="submit" value="Sign in"> 
    </div> 
</form> 

model.php

namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Auth\Passwords\CanResetPassword; 
use Illuminate\Foundation\Auth\Access\Authorizable; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 


class loginModel extends Model implements AuthenticatableContract, 
            AuthorizableContract, 
            CanResetPasswordContract 
{ 
    use Authenticatable, Authorizable, CanResetPassword; 
    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'frontend_users'; 

    protected $hidden = ['password', 'remember_token']; 
} 

route.php

Route::get('logout','Auth\[email protected]'); 
Route::controller('/','Auth\loginController'); 
Route::controller('/login', 'Auth\loginController'); 

我的問題是,當我運行我的代碼,我得到這個錯誤:

InvalidArgumentException in AuthenticatesUsers.php line 42: Undefined property frontend_users not found in auth.php 

我的配置/ auth.php

return [ 
     'multi' => [ 
      'users' => [ 
       'driver' => 'eloquent', 
       'model' => App\User::class, 
       'table' => 'users' 
      ], 
      'frontendUsers' => [ 
       'driver' => 'eloquent', 
       'model' => App\loginModel::class, 
       'table' => 'frontend_users' 
      ] 
     ], 
     'password' => [ 
       'email' => 'emails.password', 
       'table' => 'password_resets', 
       'expire' => 60, 
      ], 
     ]; 

相同的代碼在

+0

請問你'配置/ auth.php'看起來像?您定義模型的部分?而你的mode.php真的是類'loginModel'的文件名?你的模型文件名應該是'loginModel'或更好的'LoginModel',並且該類應該是'LoginModel'而不是'loginModel' –

回答

0

我見過Laravel 5的另一個項目沒有像你寫的任何方法。 \ Auth :: attempt('frontendUsers',$ userdata)。請再次閱讀文檔laravel站點中的多重認證。

Auth :: guard('frontendUsers') - > attempt($ userdata)。

+0

\ Auth :: attempt('frontendUsers',$ userdata),,,,這個工作,當我申請另一個項目..... –

0

從Laravel文檔:https://laravel.com/docs/5.1/authentication#authenticating-users

The attempt method accepts an array of key/value pairs as its first >argument. The values in the array will be used to find the user in your >database table.

你只需要通過其作爲用戶名的屬性,另一個是口令作爲參數來嘗試方法