Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tnort's avatar
Level 4

Modify model date on update or create event

Hi all,

I am currently updating an app and I am looking for a way to ensure all user emails are stored as lowercase while the first_name and last_name to ucwords which would allow me to have a standard format throughout my application data.

Is there any boot method or middleware to help me do that instead of looking for every use of model create/update methods to modify them?

thank you, Mihail

0 likes
4 replies
tnort's avatar
Level 4

@Sinnbeck, so I can actually create a boot function under the user and react to any updating, creating method call?

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@tudosm Exactly yes. And reassign the email :)

$user->email = strtolower($user->email);

For instance

    protected static function booted()
    {
        static::updating(function ($user) {
            $user->email = strtolower($user->email);
        });
    }
1 like

Please or to participate in this conversation.