Add ability to export flights of an airline only(#1375)

* Airline Flight Export

Add ability to export flights of an airline only

* StyleFix
This commit is contained in:
B.Fatih KOZ 2022-01-10 17:27:40 +03:00 committed by GitHub
parent 7799867302
commit d3b7d25abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View File

@ -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);
}
/**

View File

@ -2,8 +2,15 @@
@section('title', 'Flights')
@section('actions')
<li><a href="{{ route('admin.flights.export') }}"><i class="ti-plus"></i>Export to CSV</a></li>
<li><a href="{{ route('admin.flights.import') }}"><i class="ti-plus"></i>Import from CSV</a></li>
<li>
<a href="{{ route('admin.flights.export') }}@if(request()->get('airline_id')){{ '?airline_id='.request()->get('airline_id') }}@endif">
<i class="ti-plus"></i>
Export to CSV @if(request()->get('airline_id')) (Selected Airline) @endif
</a>
</li>
<li>
<a href="{{ route('admin.flights.import') }}"><i class="ti-plus"></i>Import from CSV</a>
</li>
<li>
<a href="{{ route('admin.flights.create') }}">
<i class="ti-plus"></i>