Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Update Users Tabel Laravel using MS SQL

Hi Experts,

I create a laravel project and using MS SQL database.

 protected function authenticated(Request $request, $user)
    {
        // $user->update([
        //     'last_login_at' => Carbon::now()->toDateTimeString(),
        //     'last_login_ip' => $request->getClientIp()
        // ]);

        // Check to see if the users account is confirmed and active
        if (! $user->isConfirmed()) {
            auth()->logout();

            // If the user is pending (account approval is on)
            if ($user->isPending()) {
                throw new GeneralException(__('exceptions.frontend.auth.confirmation.pending'));
            }

            // Otherwise see if they want to resent the confirmation e-mail

            throw new GeneralException(__('exceptions.frontend.auth.confirmation.resend', ['url' => route('frontend.auth.account.confirm.resend', e($user->{$user->getUuidName()}))]));
        }

        if (! $user->isActive()) {
            auth()->logout();

            throw new GeneralException(__('exceptions.frontend.auth.deactivated'));
        }

        event(new UserLoggedIn($user));

        if (config('access.users.single_login')) {
            auth()->logoutOtherDevices($request->password);
            // Auth::logoutOtherDevices($request->password);
        }

        
        return redirect()->intended($this->redirectPath());
    }

Open in new window


Please see these code:

    // $user->update([
        //     'last_login_at' => Carbon::now()->toDateTimeString(),
        //     'last_login_ip' => $request->getClientIp()
        // ]);

If I uncomment it then it is error.

Please the attachment.

What is wrong?

Thank you.
Error-update-users-table.PNG
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

This problem comes from the Carbon's library, please replace :

Carbon::now()->toDateTimeString()

Open in new window

By :

date("Y-m-d H:i:s")

Open in new window


And try again.
Avatar of emi_sastra
emi_sastra

ASKER

Let me see again.

Thank you.
I get this with my code.

array:2 [▼
  "last_login_at" => "2019-12-05 05:40:13"
  "last_login_ip" => "119.235.208.235"
]

Is it okay ?

Thank you.
Yes that it, looks like you're getting the right date and the right client IP address. glad I could help.
But, still get the same error.

Thank you.
I don't think so if there's an error you'll not get the array of values as you show us in the previous comment, else the error is in another part of code that is not posted in your OP.

Are you using the createFromFormat function somewhere else in your code?
Some of my friends said that it is ok using MySQL.

The Last_login_IP is work properly, after I comment the last_login_at.

Thank you.
The problem is at date column.

Thank you.
Hi Zakarian,

I use your code, and get trailing data.

Thank you.
Could you please explain more what you mean by trailing  data?
I change last_login_at to varchar(50).
the error at the attachment.

Thank you.
Please see the error.
Error-update-users-table-1.PNG
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.