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

peterdickins's avatar

Update request value

Hi,

I have a date picker on my form that allows users to select a month and year. The value is submitted as YYYY/MM. How can I update the value so that I can save it in a mysql date field?

0 likes
5 replies
Snapey's avatar

You have to apply a day (with concatenation)

$model->mydate = $request->date . '/01';

MichalOravec's avatar
Carbon\Carbon::parse($request->date.'/01')->toDateString();
peterdickins's avatar

Thanks, but how would I update the request value so it is stored in the database?

MichalOravec's avatar
$model->update([
    'date' => Carbon\Carbon::parse($request->date.'/01')->toDateString()
])
Snapey's avatar

i literally gave you the code....

Please or to participate in this conversation.