محسن مهری
4 سال پیش توسط محسن مهری مطرح شد
3 پاسخ

ثبت اخرین ورود کاربر lastlogin

سلام توی جدول user ام یک فیلد به نام last_login اضافه کردم که هر وقت کاربر login کرد توش اخرین زمان ورودش رو ثبت کنم اما نمیدونم این خط کد رو توی کجا و کدوم از کلاس های auth بزارم .لطفا راهنماییم کنید

$user->last_login = Carbon::now();
$user->update();

ثبت پرسش جدید
TEFO
تخصص : لاراول
@tefo.ha27 4 سال پیش مطرح شد
1

در کنترلر LoginController میاین متد login رو overwrite میکنین ( توی این کنترلر وجود نداره بلکه توی AuthenticatesUsers هست این متد ولی باید داخل کنترلر واردش کنین) اینم کداشه

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)) {
         // که در واقع کداتون اینجا قرار میگیره
            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);
    }

محسن مهری
تخصص : برنامه نویس back-end با زبان...
@mohsen.mehri6101 4 سال پیش مطرح شد
0

سلام @tefo.ha27 و ممنون . اگه بخوام logout رو هم ثبت کنم باید توی همین trait AuthenticatesUsers تابع logout کد هام رو قرار بدم درسته ؟


TEFO
تخصص : لاراول
@tefo.ha27 4 سال پیش مطرح شد
0

سلام توی trait نباید بزارین چون بخشی از هسته لاراوله و اگه اپدیت کنین کداتون از بین میره بلکه باید توی کنترلر این متد هایی که میخاین رو بسازین متد logout پیش فرض لاراول هم اینه


    /**
     * Log the user out of the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function logout(Request $request)
    {
        $this->guard()->logout();

        $request->session()->invalidate();

        return $this->loggedOut($request) ?: redirect('/');
    }

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام