djallits's avatar

Microseconds with Laravel's Timestamp

  • PHP 5.6.10 check!
  • MYSQL 5.6.19 check!
  • LARAVEL 5.1.7 check!

Timestamps with precision FAIL

I know it has been asked before, but I have yet to see any one say it cannot be done. Can someone point me in the right direction please?

Thank you

0 likes
4 replies
ScotchDesign1's avatar

By default, Laravel's HasTimestamps trait (vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php) uses:

public function freshTimestamp()
{
    return Date::now()->startOfSecond();
}

You can override this to remove ->startOfSecond() by redefining the function in your App\Models\Model.php file:

use Illuminate\Support\Facades\Date;
public function freshTimestamp()
{
    return Date::now();
}

Please or to participate in this conversation.