i am trying to save a input value from a time data:
x
<input type='text' name="starttime"/>
On mi example i am saving the data 3:30 for a calendar form, but to use on the calendar i need save with a “T” before the value like “T3:30”
on mi controller i save the data on the form like this:
$validatedData = $request->validate([
'titulo' => 'required|max:255',
'start' => 'required|max:255',
'starttime' => 'required|max:255', <----
'end' => 'required|max:255',
'endtime' => 'required|max:255', <----
'descripcion' => 'required|max:255',
'color' => 'required|max:255',
]);
$Calendarios=Calendarios::create($validatedData);
what could I do to save the information as I need?
Advertisement
Answer
You can create a new array after validation and then just add the ‘T’ to the starttime
of the new array. Like so:
$validatedData = $request->validate([
'titulo' => 'required|max:255',
'start' => 'required|max:255',
'starttime' => 'required|max:255',
'end' => 'required|max:255',
'endtime' => 'required|max:255',
'descripcion' => 'required|max:255',
'color' => 'required|max:255', ]);
]);
$newValidatedData = $this->validateRequest();
$newValidatedData['starttime'] = 'T' . $this->validateRequest()['starttime'];
$calendarios = Calendarios::create($newValidatedData);
Is this what you are looking for?