I have destroy function:
public function destroy(Tag $tag)
{
$tag->delete();
return Response::json([], ResponseHttp::HTTP_OK);
}
If frontend send one id of post - all ok. But how delete if frontend send array of post?
I have destroy function:
public function destroy(Tag $tag)
{
$tag->delete();
return Response::json([], ResponseHttp::HTTP_OK);
}
If frontend send one id of post - all ok. But how delete if frontend send array of post?
Try it,if you can get array of ids then you will delete them as
public function destroyArrayOfTag(array $tag){ //you can also use Request for getting post attributes
Tag::whereIn('id',$tag)->delete();
return Response::json([], ResponseHttp::HTTP_OK);
}
where $tag is a array of ids. Best of luck
I do it from filter -
public function destroy()
{
Tag::filter(\Request::only(['filter']))->delete();
return Response::json([], ResponseHttp::HTTP_OK);
}
You could also pass an array of ids using a delimiter. eg. comma
So your route would look like this destroy/1,2,3,4
Then in your controller:
public function destroy($ids)
{
Tag::destroy(explode(",",$ids));
return Response::json([], ResponseHttp::HTTP_OK);
}
EDIT: You are using DELETE
method, so your url would look something like this api/tag/1,2,3
perhaps you should add an array variable in your ajax. example like this :
var data =[];
and then fetch the array post into data. and then you can do this thing :
for(var i=0; i<data.length; i++)
{
$.ajax({
url: your_path+'/destroy/'+data[i],
type: 'GET',
dataType: 'json',
success:function(response) {
notify(1,"Your Response Message");
}
})
}
Hope this will help you. Thank's