我需要自定义身份验证,即:
LoginController
的自定义模型和数据库表(已解决)因为我不理解credentials
方法机制,所以我收到错误:
Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials()
must be an instance of Illuminate\Contracts\Auth\Authenticatable,
instance of App\Order given, called in C:\OpenServer\domains\sites-in-development.loc\vendor\laravel\framework\src\Illuminate\Auth\SessionGuard.php on line
<?php
class LoginController extends Controller {
use AuthenticatesUsers;
protected $redirectTo;
protected $orderAlias;
protected $loginView;
/*
Here I set the order ID as "username". I don't like this method,
because it causes the confusion ($username is actually order ID),
but don't know the other way yet.
REF is just the class with array contains the string values to avoid hardcoding
*/
protected $username = REF::tables['orders']['fieldNames']['orderId'];
public function __construct() {
$this->middleware('guest')->except('logout');
$this->loginView = '00_top';
}
public function showLoginForm() {
// Work properly
}
public function login(Request $request) {
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
// manual validation (work properly)
// getting $orderAlias from DB
$redirectTo = '/'.$orderAlias;
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request); // to "credentials"...
}
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
protected function credentials(Request $request) {
// here is error
return $request->only(REF::forms['loginToOrder']['fieldNames']['orderID'],
REF::forms['loginToOrder']['fieldNames']['password']);
}
}