From d3b7d25abde55412bcd5005d19776c4e02fee9c1 Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" Date: Mon, 10 Jan 2022 17:27:40 +0300 Subject: [PATCH] Add ability to export flights of an airline only(#1375) * Airline Flight Export Add ability to export flights of an airline only * StyleFix --- app/Http/Controllers/Admin/FlightController.php | 16 ++++++++++------ resources/views/admin/flights/index.blade.php | 11 +++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php index 17735455..783cc827 100644 --- a/app/Http/Controllers/Admin/FlightController.php +++ b/app/Http/Controllers/Admin/FlightController.php @@ -300,14 +300,18 @@ class FlightController extends Controller public function export(Request $request) { $exporter = app(ExportService::class); - $flights = $this->flightRepo->all(); + + $where = []; + $file_name = 'flights.csv'; + if ($request->input('airline_id')) { + $airline_id = $request->input('airline_id'); + $where['airline_id'] = $airline_id; + $file_name = 'flights-'.$airline_id.'.csv'; + } + $flights = $this->flightRepo->where($where)->get(); $path = $exporter->exportFlights($flights); - return response() - ->download($path, 'flights.csv', [ - 'content-type' => 'text/csv', - ]) - ->deleteFileAfterSend(true); + return response()->download($path, $file_name, ['content-type' => 'text/csv'])->deleteFileAfterSend(true); } /** diff --git a/resources/views/admin/flights/index.blade.php b/resources/views/admin/flights/index.blade.php index 7857beb9..5242db27 100644 --- a/resources/views/admin/flights/index.blade.php +++ b/resources/views/admin/flights/index.blade.php @@ -2,8 +2,15 @@ @section('title', 'Flights') @section('actions') -
  • Export to CSV
  • -
  • Import from CSV
  • +
  • + + + Export to CSV @if(request()->get('airline_id')) (Selected Airline) @endif + +
  • +
  • + Import from CSV +