我有點困惑的代碼。在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,
],
];
相同的代碼在
請問你'配置/ auth.php'看起來像?您定義模型的部分?而你的mode.php真的是類'loginModel'的文件名?你的模型文件名應該是'loginModel'或更好的'LoginModel',並且該類應該是'LoginModel'而不是'loginModel' –