这是我的ajax请求。我发送请求到控制器删除图片
$(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();
});
});
});
它有效。所以如果请求响应200(ok)页面将被重新加载。但我有另一个表单字段,并在重新加载后,我想保存(闪存)这些字段的值。所以在控制器中我返回输入,但它返回空数组。这是我的控制器
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();
}
我应该如何使用他们的数据返回所有输入字段?我也试过这些
$request->all();
$request->flash();
redirect()->back()->withInput();
但结果是一样的。