mardi 2 février 2016

Input::all() returns empty array in laravel 5

here's my ajax request. i send request to controller to remove pictures

   $(document).on("click", "button[data-delete]", function(e) {
    var tour_id = $("form").attr("data-tour-id");
    var gallery = {};
    $("input:checkbox[class = checkbox]:checked").each(function(k){
        gallery[k] = $(this).attr("data-gallery-id");
    });
    gallery = JSON.stringify(gallery);
    bootbox.confirm({
        message: "გსურთ აღნიშნული სურათის წაშლა?",
        callback: function(result){ }
    });
    $("button[data-bb-handler='confirm']").on("click",function(){
        $.ajax({
            headers: {'X-CSRF-Token': $('meta[name="csrf_token"]').attr('content')},
            url: "/{lang}/admin/tours/"+ tour_id +"/edit/removeGalleryPic/"+ gallery,
            data : { id: tour_id, pics: gallery },
        }).done(function() {
            window.location.reload();
        });
    });
});

it works. so if request response 200(ok) page will be reloaded. but i have another form fields, and after being reloaded i want to save(flash) the values of these fields. so in controller i return input, but it returns empty array. here's my controller

public function removeGalleryPic($id, $pics)
{
    $pics = json_decode($pics, true);
    $tour_whole_gallery = Tour_gallery::where("tour_id", $id)->get();
    if(count($tour_whole_gallery) > 0)
    {
        foreach($tour_whole_gallery as $gallery)
        {
            foreach($pics as $pic_id)
            {
                if($gallery->id == $pic_id)
                {
                    unlink(public_path() . $gallery->path);
                    Tour_gallery::where("id", $pic_id)->delete();
                }
            }
        }
    }
    return Input::all();
}

how should i return all input fields with their data? i also tried these

$request->all();
$request->flash();
redirect()->back()->withInput();

but result is the same.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire