I have a form in that I want to create a date from three fields. The first "date" field comes from a JavaScript plugin. The next is a simple hour field with a choice of 0 through 23. The next is a "minutes" field with choices of 00,10,20,30,40,50.
The code in my controller appears to work. If I do a dd($formFields) just before the update, the new value for pub_date shows as the date I created from the three parts.:
"pub_date" => "2022-08-26 04:00"
To be clear, I am attempting to overwrite the value of the original form field, which contains only a date and replace it with my newly created date and time.
When I run the update from the blade, it updates all the other fields but just skips the "pub_date" field. What am I missing?
This is my controller.
public function update(Request $request, pibs $pibs)
{
$formFields = $request->validate([
'addr_number' => ['required'],
'addr_street' => ['required'],
'addr_city' => ['required'],
'addr_state' => ['required'],
'addr_postalcode' => ['required'],
'addr_lat' => ['nullable'],
'addr_lng' => ['nullable'],
'tags' => ['nullable'],
'pub_date' => ['nullable']
]);
if ($request->pub_date != null ){
$combined_date_and_time = $request->pub_date . ' ' . $request->pub_hour . ':' . $request->pub_minute . ':00';
$new_pub_date = Carbon::parse($combined_date_and_time);
$formFields['pub_date'] = $new_pub_date->format('Y-m-d h:i');
}
$pibs->update($formFields);
$pibs->save();
return back()->with('message', 'Building Survey updated successfully!');
}