Redirect::route with long parameters works locally but not on server

Hello. I have been trying to find a solution for exporting a PDF with the information on the table seen but with the filtered data. To do so, I do a return Redirect::route passing thedata and arrays, which is quite long, but works fine locally. My code is this:
public function exportToPdf($modelType)
{
$query = $this->getFilteredTableQuery();
$this->applySortingToTableQuery($query);
$SortColumn = $this->getTableSortColumn();
$SortDirection = $this->getTableSortDirection();
$stocks = $query->get()->toArray();
return Redirect::route('pdf.export', ['stocks' => $stocks, 'model' => $modelType, 'sortColumn' => $SortColumn, 'sortDirection' => $SortDirection]);
}
public function exportToPdf($modelType)
{
$query = $this->getFilteredTableQuery();
$this->applySortingToTableQuery($query);
$SortColumn = $this->getTableSortColumn();
$SortDirection = $this->getTableSortDirection();
$stocks = $query->get()->toArray();
return Redirect::route('pdf.export', ['stocks' => $stocks, 'model' => $modelType, 'sortColumn' => $SortColumn, 'sortDirection' => $SortDirection]);
}
I have been working a lot to achieve this and now it works fine locally but when I have deployed to the server it throws an uncontrolled error "THIS WEBSITE CANNOT BE ACCESSED". The result of the redirect is very long, as you can see in the attached image. Any ideas of how can I solve this or get around to the way I send the FILTERED info to the controller? This is my controller, which gets the filtered array:
public function exportPdf(Request $request)
{
$list_model = $request->input('model');
$filteredStocks = $request->input('stocks');
$filteredStocks = collect($filteredStocks);
$filteredStocks = $filteredStocks->pluck('id');

$sortColumn = $request->input('sortColumn');
$sortDirection = $request->input('sortDirection');
$stocks = Stock::with('rawMaterial','warehouse','supplier')->whereIn('id',$filteredStocks)->orderBy($sortColumn, $sortDirection)->get();

$soloWareHouse = false;
$different_warehouses=$stocks->groupBy("warehouse_id")->count();

if($different_warehouses==1){
$soloWareHouse = true;
}

$viewName = 'stockpdf.export-without-prices';
$filename = 'inventory_report '. date('Y-m-d'). '.pdf';
$pdf = PDF::loadView($viewName, ['stocks' => $stocks, 'list_model' => $list_model, 'soloWareHouse' => $soloWareHouse])->setPaper('a4', 'landscape');
// Set the PDF filename and headers

$headers = [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'. $filename. '"',
];

// Return the PDF response
return response()->make($pdf->stream(), 200, $headers);
}
public function exportPdf(Request $request)
{
$list_model = $request->input('model');
$filteredStocks = $request->input('stocks');
$filteredStocks = collect($filteredStocks);
$filteredStocks = $filteredStocks->pluck('id');

$sortColumn = $request->input('sortColumn');
$sortDirection = $request->input('sortDirection');
$stocks = Stock::with('rawMaterial','warehouse','supplier')->whereIn('id',$filteredStocks)->orderBy($sortColumn, $sortDirection)->get();

$soloWareHouse = false;
$different_warehouses=$stocks->groupBy("warehouse_id")->count();

if($different_warehouses==1){
$soloWareHouse = true;
}

$viewName = 'stockpdf.export-without-prices';
$filename = 'inventory_report '. date('Y-m-d'). '.pdf';
$pdf = PDF::loadView($viewName, ['stocks' => $stocks, 'list_model' => $list_model, 'soloWareHouse' => $soloWareHouse])->setPaper('a4', 'landscape');
// Set the PDF filename and headers

$headers = [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'. $filename. '"',
];

// Return the PDF response
return response()->make($pdf->stream(), 200, $headers);
}
Maybe my approach is incorrect but it is working locally for me. Any ideas will be highly appreciated. Thank you.
1 Reply
Albert Lens
Albert LensOP4mo ago
I have considerably reduced the size of the url and now it works, though I think this is not the right approach.
public function exportToPdf($modelType)
{
$query = $this->getFilteredTableQuery();
$this->applySortingToTableQuery($query);
$SortColumn = $this->getTableSortColumn() ?? 'id';
$SortDirection = $this->getTableSortDirection() ?? 'desc';
$stocks = $query->pluck('id')->toArray(); //NOW I ONLY GET COLUMN ID and not all columns
// $stocks = $stocks->toArray();
return Redirect::route('pdf.export', ['stocks' => $stocks, 'model' => $modelType, 'sortColumn' => $SortColumn, 'sortDirection' => $SortDirection]);
}
public function exportToPdf($modelType)
{
$query = $this->getFilteredTableQuery();
$this->applySortingToTableQuery($query);
$SortColumn = $this->getTableSortColumn() ?? 'id';
$SortDirection = $this->getTableSortDirection() ?? 'desc';
$stocks = $query->pluck('id')->toArray(); //NOW I ONLY GET COLUMN ID and not all columns
// $stocks = $stocks->toArray();
return Redirect::route('pdf.export', ['stocks' => $stocks, 'model' => $modelType, 'sortColumn' => $SortColumn, 'sortDirection' => $SortDirection]);
}
Anyhow, I still think this is not the right approach because when user has thousands of records filtered, I do not know whether the url size will work on production server. Please any ideas of the right approach to pass FILTERED table data to CONTROLLER ? Tks.
Want results from more Discord servers?
Add your server