mercredi 9 mars 2016

How to dispaly a confirm box before updating a form in laravel 5?

Here is my controller method given below,

public function edit1(Requests\EventRequest $request){

    $date=$_POST['eventDate'];
    $title=$_POST['title'];
    $id=$_POST['id'];
    Alert::success('', 'Do you want to Update?');
    $events=EventCal::findOrFail($id);

  $events->update($request->all());

 DB::table('event_cals')
        ->where('id',$id)
        ->update(['title' => $title,'eventDate' => $date]);



    return redirect('/dcalendar');
}

Here is the custom view of sweet-alert:

    @if (Session::has('sweet_alert.showConfirmButton'))
    <script>

    swal({
        title: "{!! Session::get('sweet_alert.title') !!}",
        text: "{!! Session::get('sweet_alert.text') !!}",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, Update it!",
        cancelButtonText: "No, cancel update!",
        closeOnConfirm: false,
        closeOnCancel: false
    }, function(isConfirm){
    if (isConfirm) {
    swal("Updated!", "Your imaginary file has been updated.", "success");
    } else {
    swal("Cancelled", "Your imaginary file is not updated :)", "error");
    }
    });
    </script>
@endif

This will appear the confirm box but not before the updation. Please can anybody help me?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire