2017-06-09 09:37:51 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
use App\Models\Subfleet;
|
2017-06-09 09:37:51 +08:00
|
|
|
use App\Http\Requests\CreateAircraftRequest;
|
|
|
|
use App\Http\Requests\UpdateAircraftRequest;
|
2017-06-25 03:00:56 +08:00
|
|
|
use App\Repositories\AircraftRepository;
|
2017-06-09 09:37:51 +08:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Flash;
|
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
2017-12-02 22:29:53 +08:00
|
|
|
|
2017-06-09 09:37:51 +08:00
|
|
|
|
2017-06-11 11:17:45 +08:00
|
|
|
class AircraftController extends BaseController
|
2017-06-09 09:37:51 +08:00
|
|
|
{
|
2017-12-02 22:29:53 +08:00
|
|
|
private $aircraftRepository;
|
2017-06-09 09:37:51 +08:00
|
|
|
|
2017-06-25 00:09:27 +08:00
|
|
|
public function __construct(
|
2017-12-02 22:29:53 +08:00
|
|
|
AircraftRepository $aircraftRepo
|
2017-06-25 00:09:27 +08:00
|
|
|
) {
|
2017-06-09 09:37:51 +08:00
|
|
|
$this->aircraftRepository = $aircraftRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the Aircraft.
|
2018-01-10 03:34:19 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2017-06-09 09:37:51 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->aircraftRepository->pushCriteria(new RequestCriteria($request));
|
|
|
|
$aircraft = $this->aircraftRepository->all();
|
|
|
|
|
2017-12-02 22:29:53 +08:00
|
|
|
return view('admin.aircraft.index', [
|
2017-12-30 07:34:09 +08:00
|
|
|
'aircraft' => $aircraft
|
2017-12-02 22:29:53 +08:00
|
|
|
]);
|
2017-06-09 09:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new Aircraft.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2017-06-23 09:55:45 +08:00
|
|
|
return view('admin.aircraft.create', [
|
|
|
|
'subfleets' => Subfleet::all()->pluck('name', 'id'),
|
|
|
|
]);
|
2017-06-09 09:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Aircraft in storage.
|
2018-01-10 03:34:19 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-09 09:37:51 +08:00
|
|
|
*/
|
|
|
|
public function store(CreateAircraftRequest $request)
|
|
|
|
{
|
|
|
|
$input = $request->all();
|
2018-02-13 00:26:27 +08:00
|
|
|
$aircraft = $this->aircraftRepository->create($input);
|
2017-06-09 09:37:51 +08:00
|
|
|
|
|
|
|
Flash::success('Aircraft saved successfully.');
|
2018-02-13 00:26:27 +08:00
|
|
|
return redirect(route('admin.aircraft.edit', ['id' => $aircraft->id]));
|
2017-06-09 09:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Aircraft.
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($aircraft)) {
|
|
|
|
Flash::error('Aircraft not found');
|
|
|
|
return redirect(route('admin.aircraft.index'));
|
|
|
|
}
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
return view('admin.aircraft.show', [
|
2017-06-25 00:09:27 +08:00
|
|
|
'aircraft' => $aircraft,
|
2017-06-23 09:55:45 +08:00
|
|
|
]);
|
2017-06-09 09:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified Aircraft.
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($aircraft)) {
|
|
|
|
Flash::error('Aircraft not found');
|
|
|
|
return redirect(route('admin.aircraft.index'));
|
|
|
|
}
|
|
|
|
|
2017-06-23 09:55:45 +08:00
|
|
|
return view('admin.aircraft.edit', [
|
|
|
|
'subfleets' => Subfleet::all()->pluck('name', 'id'),
|
2017-06-25 00:09:27 +08:00
|
|
|
'aircraft' => $aircraft,
|
2017-06-23 09:55:45 +08:00
|
|
|
]);
|
2017-06-09 09:37:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified Aircraft in storage.
|
2018-01-10 03:34:19 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-09 09:37:51 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdateAircraftRequest $request)
|
|
|
|
{
|
|
|
|
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($aircraft)) {
|
|
|
|
Flash::error('Aircraft not found');
|
|
|
|
return redirect(route('admin.aircraft.index'));
|
|
|
|
}
|
|
|
|
|
2017-12-02 22:29:53 +08:00
|
|
|
$this->aircraftRepository->update($request->all(), $id);
|
|
|
|
|
2017-06-09 09:37:51 +08:00
|
|
|
Flash::success('Aircraft updated successfully.');
|
|
|
|
return redirect(route('admin.aircraft.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Aircraft from storage.
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$aircraft = $this->aircraftRepository->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($aircraft)) {
|
|
|
|
Flash::error('Aircraft not found');
|
|
|
|
return redirect(route('admin.aircraft.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->aircraftRepository->delete($id);
|
|
|
|
|
|
|
|
Flash::success('Aircraft deleted successfully.');
|
|
|
|
return redirect(route('admin.aircraft.index'));
|
|
|
|
}
|
|
|
|
}
|