Export flights to CSV in admin #194

This commit is contained in:
Nabeel Shahzad
2018-03-21 17:07:30 -05:00
parent 95a7365fee
commit 276b93fc57
10 changed files with 404 additions and 30 deletions

View File

@@ -15,6 +15,7 @@ use App\Repositories\FareRepository;
use App\Repositories\FlightFieldRepository;
use App\Repositories\FlightRepository;
use App\Repositories\SubfleetRepository;
use App\Services\ExporterService;
use App\Services\FareService;
use App\Services\FlightService;
use App\Services\ImporterService;
@@ -310,6 +311,27 @@ class FlightController extends Controller
return redirect(route('admin.flights.index'));
}
/**
* Run the flight exporter
* @param Request $request
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
* @throws \League\Csv\Exception
*/
public function export(Request $request)
{
$exporter = app(ExporterService::class);
$path = storage_path('app/import/export_flight.csv');
$flights = $this->flightRepo->all();
$exporter->exportFlights($flights, $path);
return response()
->download($path, 'flights.csv', [
'content-type' => 'text/csv',
])
->deleteFileAfterSend(true);
}
/**
*
* @param Request $request