dimanche 1 septembre 2019

Duplicate function update

I am trying to create a duplicate system, I have a form revision with a recording.

For example, I have to change the value of my field hour_start => 18:00

enter image description here

I want to replace by the value => 08:00

enter image description here

When, I validate the form I have an error message:

enter image description here

The value of my field hour start is always the same

enter image description here

In fact, my duplicate system must work for dates, but if I change a value of my field hour_start, it must pass...

public function update(revisionRequest $request, $id)
    {

        $exists = Revision::where('date_revision_start', $request->get('date_revision_start'))->where('date_revision_end', $request->get('date_revision_end'))->where('hour_start', $request->get('hour_start'))->where('hour_end', $request->get('hour_end'))->where('fk_motorbike', $request->get('fk_motorbike'))->where('fk_garage', $request->get('fk_garage'))->count();

        $date_revision_start = $request->get('date_revision_start');
        $date_revision_end = $request->get('date_revision_end');

        $conflict = Revision::where('fk_motorbike', $request->get('fk_motorbike'))->whereDate('date_revision_start', "<=" , $date_revision_start)
            ->whereDate('date_revision_end', ">=", $date_revision_start)
            ->first();

        $conflict2 = Revision::where('fk_motorbike', $request->get('fk_motorbike'))->whereDate('date_revision_start', "<=" , $date_revision_end)->whereDate('date_revision_end', ">=", $date_revision_end)->first();

        if(isset($conflict2) || isset($conflict)){
            return redirect()->route('revisions.index')
             ->with('error', 'Duplicate date! ');
        }


        else{
            $revisions = Revision::find($id);
            $revisions->date_revision_start = $request->get('date_revision_start');
            $revisions->date_revision_end = $request->get('date_revision_end');
            $revisions->hour_start = $request->get('hour_start');
            $revisions->hour_end = $request->get('hour_end');
            $revisions->fk_garage = $request->get('fk_garage');
            $revisions->fk_motorbike = $request->get('fk_motorbike');
            $revisions->save();
            return redirect()->route('revisions.index')
                    ->with('success', 'ok')->withInput();
        }

    } 

Thank you for your help.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire