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

fastforward's avatar

date format and mail queueing

Hello I have some glitches with date formating in latest laravel version. I used laravel migration timestamps() for table, date works fine until i try to add ->format() to created_at column, whenever i try it just respond with this error: Fatal error: Call to a member function format() on string, I have no clue why it doesn't work, on updated_at column it works fine, but on created_at it don't.

And second mail queueing, I tried events and jobs for it, but it always works as just plain sending making my request longer, I just wan't to make that whenever someone registers then mail is being sent after he did register request. Not when he pressed registration button.

In job file handle code:

public function handle(Mailer $mailer)
{
        $user = $this->user;

        $mailer->queue('emails.user-confirmation', ['user' => $user], function($mail) use ($user) {
            $mail->to($user->email);
            $mail->subject('Account confirmation');
        });
 }
0 likes
5 replies
Mariam's avatar

This works for me

$user->created_at->format('d M Y - H:i:s');
fastforward's avatar

@Mariam But it doesn't for me and its only for this one table, for other tables everything works fine. I wouldn't ask for help if updated_at column would show same error as created_at.

richard's avatar

That's weird. What if you place this on the User model.

protected $dates = ['created_at','updated_at'];

For mail queueing, try this. Ensure that your Queue Driver is database and you have a cron jon to run queue:listen Artisan command.

 $mailer->later(5, 'emails.user-confirmation', ['user' => $user], function($mail) use ($user) {
            $mail->to($user->email);
            $mail->subject('Account confirmation');
        });
fastforward's avatar
fastforward
OP
Best Answer
Level 1

Seems like migration with removing and adding those columns back again fixed this problem, no clue why it wasn't working at first, but now its working. Thanks for help.

Please or to participate in this conversation.