2 回答

TA貢獻1735條經驗 獲得超5個贊
為什么不覆蓋 authController 中的登錄方法??????像這樣
public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if (method_exists($this, 'hasTooManyLoginAttempts') &&
$this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
$user = auth()->guard('web')->user();
//$user = auth()->guard('api')->user();
$user->last_login = now()->toDateTimeString();
$user->save();
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}

TA貢獻1835條經驗 獲得超7個贊
最后我可以做到,我在函數句柄中使用 WHERE,具體來說
app\Listeners\UpdateLastSignInAt
<?php
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Carbon\Carbon;
class UpdateLastSignInAt
{
public function __construct()
{
//
}
public function handle(Login $event)
{
$date = Carbon::now();
$user = $event->user->ID;
User::where('ID', $user)
->update(['LAST_LOGIN' => $date]);
}
}
- 2 回答
- 0 關注
- 164 瀏覽
添加回答
舉報