I am trying to save a date from jQuery UI datepicker to database.
I want to display the date in m/d/Y format on date selection from the input form.
When I try to save it to the database, it is giving the following error: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value
I have followed a lot of solutions, however it is not working for me.
I have looked through this link, though I followed everything correctly, it is still returning the same error.
Controller Code
public function store(Request $request)
{
$user = Frontend::create($request->all());
}
Model Code
class Frontend extends Model
{
use HasFactory;
protected $table = 'frontend';
protected $fillable = ['date'];
public function setDateAtttribute($date)
{
$this->attributes['date'] = Carbon::createFromFormat($date)->format('Y-m-d');
}
}
config>app.php
'date_format' => 'm/d/Y',
'date_format_javascript' => 'mm/dd/yy',
I am new to this and it would be a huge help if anyone could help me find the solution.