vendredi 1 décembre 2017

a Double data type conversion to Time and Time to Double in Laravel and PHP

I'm using double data type value name as $duration to calculate a time different in Laravel application, so I have to make a data type conversion code from Double to Time format.

How do I fix the code? below was not worked. thanks.

in the view

<div class="form-group col-sm-12 col-lg-12">
<label for="duration">Edit used time: </label>
<input id="duration" type="time" name="duration" 
       value="" class="form-control">
</div>

in the controller

public function update($id, UpdateJobRequest $request)
{
    $job = Job::onlyTrashed()->find($id);

    if (empty($job)) {
        Flash::error('Job not found');

        return redirect(route('stopjobs.index'));
    }
     $duration = $request->duration;
     $duration_value = (double)$duration; 

     $job = $job->update([
        "note_1" => $request->note_1, 
        "duration" => $request->duration,
        "job_place" => $request->job_place,
        "job_type" => $request->job_type,
        "duration" => $duration_value            
        ]);        

    // $job = $job->update(array($request->all()));


    Flash::success('Job updated successfully.');

    return redirect(route('stopjobs.index'));
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire