@nickywan123 I think you need to pass the file name of the zip file, not the zip object class, like:
return response()->download('file.zip');
But make sure you are passing the correct path.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a table with list of orders where each order have their own airway bill note. The airway note is actually an external URL(given by API response) where if I click on it, it will present a download box to user to download and save the file. I now wanted to allow the user to select multiple consignment notes so they can download in bulk.
I thought of having a checkbox for user to select and then in my controller, create a zip file and add those airway to it and return it to the user to download. Currently, I am using this zip package by zanysoft/laravel-zip. I am not too sure if it allows to add external URL inside the zip file.
Here is my Ajax request:
$('.download_bulk').on('click', function(e) {
e.preventDefault();
let allVals = [];
$(".subChkOrder:checked").each(function() {
allVals.push($(this).attr('data-id'));
});
if( allVals.length <= 1 ) {
alert("Please select more than 1 row.");
} else {
let join_selected_values = allVals.join(",");
$.ajax({
url:"{{route('order.print.bulk')}}",
type: 'POST',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: 'ids='+join_selected_values,
success: function (data) {
//window.location = data;
if(data['success']) {
alert(data['data']);
} else if (data['error']) {
alert(data['error']);
} else {
alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});
}
});
And in my controller:
public function printBulkConsignment(Request $request){
$ids = $request->ids;
$datas = Order::whereIn('id', explode(',', $ids))->get();
$consignments= array();
foreach($datas as $data){
$consignments[] = '"'.$data->awb_id_link.'"';
}
$zip = Zip::create('file.zip');
$zip->add($consignments);
$zip->close();
$data = json_encode($zip);
return response()->download($zip);
//return response()->json(['success' => 'Print bulk success', 'data' =>$data]);
}
The awb_id_link is external URL like "https:..../external_url/path_to_download" Upon submitting the request, the alert keeps showing an error:
message : Object of class Zanysoft\Zip could not be converted to string
I am not too sure why the user is unable to download the zip, how do I solve it?
Please or to participate in this conversation.