Level 2
I'm new in Laravel, but I think that you may not use 'd/m/Y' format to save in database. You must use 'Y-m-d' format.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I need to automatically insert created_at column with manual date for some rules, but it always return
Could not parse '16/01/2023': DateTime::__construct(): Failed to parse time string (16/01/2023) at position 0 (1): Unexpected character
Here is my model,
protected static function boot() {
parent::boot();
if(Gate::allows('engineer_progress_manual_date')) {
static::creating(function ($model) {
// $model->created_at = Carbon::createFromFormat('d/m/Y H:i:s', request('created_at').' '.date('H:i:s'))->format('Y-m-d H:i:s');
$model->created_at = DateTime::createFromFormat('d/m/Y H:i:s', request('created_at').' '.date('H:i:s'));
});
static::updating(function ($model) {
// $model->created_at = Carbon::createFromFormat('d/m/Y H:i:s', request('created_at').' '.date('H:i:s'))->format('Y-m-d H:i:s');
$model->created_at = DateTime::createFromFormat('d/m/Y H:i:s', request('created_at').' '.date('H:i:s'));
});
}
}
Please or to participate in this conversation.