Skip to content

Inconsistent timestamps format for User model on Logout #52086

Closed
@Aniket-IN

Description

@Aniket-IN

Laravel Version

10.45.0

PHP Version

8.2.18

Database Driver & Version

No response

Description

I noticed a weird issue, when a user tries to logout from my Laravel Application. Laravel updates the remember_token.
Which results in Scout updating the data on it's index, and I noticed the timestamp format is not always same.

On that update Laravel sets $user->timestamps to false which disables the casting for created_at and updated_at fields.
This line:

$user->timestamps = false;

Which eventually leads to inconsistant format for the timestamp fields.

Usually the format is like this: 2023-09-05T18:23:38.000000Z but, only on that instance (when Laravel updates the remember_token) the format is like this: 2023-09-05 18:23:38

When Laravel updates the User model on Logout:
image

When I update the User model from any other place:
image

Steps To Reproduce

  1. Start a new Laravel project with Breeze (Blade)
  2. Configure Laravel Scout (any driver)
  3. Register a User
  4. Login to the dashboard
  5. Create the toSearchableArray() method in User model, and add a dd($this->created_at)
    public function toSearchableArray(): array
    {
        dd($this->created_at);
    }
  1. Now logout from the dashboard it will show the dd() output, (Note this 📝)
  2. Next, from any other controller try updating a User User::find(1)->update(['name' => "Foo Bar"]);
  3. Run this code, it will show the dd() output, (Note this 📝)

Compare the output of Step 6 and Step 8
Those should be different.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions