AA
This commit is contained in:
@@ -290,6 +290,8 @@ class ArticleController extends Controller
|
||||
->orderBy('totVen', 'desc')
|
||||
->get();
|
||||
|
||||
|
||||
|
||||
if ($articoliVenduti->isEmpty()) {
|
||||
return response()->json(['message' => 'Nessun articolo trovato.'], 404);
|
||||
}
|
||||
@@ -299,7 +301,8 @@ class ArticleController extends Controller
|
||||
return response()->json(['error' => 'Si è verificato un errore durante il recupero dei dati: ' . $e->getMessage()], 500);
|
||||
}
|
||||
|
||||
return $articoliVenduti;
|
||||
// Restituisci una risposta JSON con i dati
|
||||
return response()->json(['data' => $articoliVenduti]);
|
||||
|
||||
}
|
||||
private function queryArticlesFatturati()
|
||||
@@ -564,10 +567,14 @@ class ArticleController extends Controller
|
||||
$articoliVenduti = $this->queryArticlesFatturati();
|
||||
} else {
|
||||
$articoliVenduti = $this->queryArticlesSales();
|
||||
// ritorna response()->json(['data' => $articoliVenduti]);
|
||||
}
|
||||
|
||||
if ($articoliVenduti->isNotEmpty()) {
|
||||
if ($articoliVenduti->isEmpty()) {
|
||||
return response()->json(['message' => 'Nessun articolo trovato.'], 404);
|
||||
} else {
|
||||
|
||||
// ho i dati in "articoliVenduti->data"
|
||||
// Mappa i risultati nella struttura JSON desiderata
|
||||
$result = $articoliVenduti->map(function ($articoloVenduto) {
|
||||
return [
|
||||
@@ -604,8 +611,6 @@ class ArticleController extends Controller
|
||||
$response->headers->set('Content-Disposition', 'attachment; filename="ranking_' . $cosa . '_' . date('Y-m-d') . '.json"');
|
||||
|
||||
return $response;
|
||||
} else {
|
||||
return new Response('Nessun articolo', 500);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user