In laravel 5.8 / axios "^0.18", "vue": "^2.5.17" app I use Maatwebsite\Excel to upload csv file It works in case I run laravel control in GET request, but I use axios for post requests and running request the file is not downloaded at all. I run my request in JS code :
axios({
method: ( 'post' ),
url: this.$store.getters.apiUrl + '/personal/run-user-list-export-to-csv',
data: { user_id : user_id, user_list_id: user_list_id },
}).then((response) => {
this.showPopupMessage("User list export", "User list successfully exported !", 'success');
}).catch((error) => {
this.showPopupMessage("User list export", 'Error exporting user\'s list !', 'error');
});
with control :
public function run_user_list_export_to_csv() // http://127.0.0.1:8000/api/run-user-list-export-to-csv
{
$request= request();
...
$ret= \Excel::download(new exportSearchResults($user_list_id), 'file.csv'); // if write RETURN this line file is not downloaded anyway...
return response()->json( ['error_code' => 1, 'message' => '', 'ret' => $ret, HTTP_RESPONSE_INTERNAL_SERVER_ERROR ] );
} // public function storerun_user_list_export_to_csv(UserLisRequest $request)
I browser's responce I see output :
{"error_code":1,"message":"","ret":{"headers":{}},"0":500}
But file is not downloaded. How correctly?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire