phpvms/app/Http/Controllers/Admin/PirepController.php

166 lines
3.9 KiB
PHP
Raw Normal View History

2017-06-29 08:54:05 +08:00
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\CreatePirepRequest;
use App\Http\Requests\UpdatePirepRequest;
2017-07-14 11:09:38 +08:00
use App\Repositories\AircraftRepository;
2017-06-29 08:54:05 +08:00
use App\Repositories\PirepRepository;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
class PirepController extends BaseController
{
2017-07-14 11:09:38 +08:00
private $pirepRepo, $aircraftRepo;
2017-06-29 08:54:05 +08:00
2017-07-14 11:09:38 +08:00
public function __construct(PirepRepository $pirepRepo, AircraftRepository $aircraftRepo)
2017-06-29 08:54:05 +08:00
{
2017-07-14 11:09:38 +08:00
$this->aircraftRepo = $aircraftRepo;
$this->pirepRepo = $pirepRepo;
}
public function aircraftList()
{
$retval = [];
$all_aircraft = $this->aircraftRepo->all();
foreach ($all_aircraft as $ac) {
$retval[$ac->id] = $ac->subfleet->name.' - '.$ac->name.' ('.$ac->registration.')';
}
return $retval;
2017-06-29 08:54:05 +08:00
}
/**
* Display a listing of the Pirep.
*
* @param Request $request
* @return Response
*/
public function index(Request $request)
{
2017-07-14 11:09:38 +08:00
$this->pirepRepo->pushCriteria(new RequestCriteria($request));
$pireps = $this->pirepRepo->all();
2017-06-29 08:54:05 +08:00
return view('admin.pireps.index', [
'pireps' => $pireps
]);
}
/**
* Show the form for creating a new Pirep.
*
* @return Response
*/
public function create()
{
return view('admin.pireps.create');
}
/**
* Store a newly created Pirep in storage.
*
* @param CreatePirepRequest $request
*
* @return Response
*/
public function store(CreatePirepRequest $request)
{
$input = $request->all();
2017-07-14 11:09:38 +08:00
$pirep = $this->pirepRepo->create($input);
2017-06-29 08:54:05 +08:00
Flash::success('Pirep saved successfully.');
return redirect(route('admin.pireps.index'));
}
/**
* Display the specified Pirep.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
2017-07-14 11:09:38 +08:00
$pirep = $this->pirepRepo->findWithoutFail($id);
2017-06-29 08:54:05 +08:00
if (empty($pirep)) {
Flash::error('Pirep not found');
return redirect(route('admin.pireps.index'));
}
return view('admin.pireps.show', [
'pirep' => $pirep,
]);
}
/**
* Show the form for editing the specified Pirep.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
2017-07-14 11:09:38 +08:00
$pirep = $this->pirepRepo->findWithoutFail($id);
2017-06-29 08:54:05 +08:00
if (empty($pirep)) {
Flash::error('Pirep not found');
return redirect(route('admin.pireps.index'));
}
return view('admin.pireps.edit', [
'pirep' => $pirep,
2017-07-14 11:09:38 +08:00
'aircraft' => $this->aircraftList(),
2017-06-29 08:54:05 +08:00
]);
}
/**
* Update the specified Pirep in storage.
*
* @param int $id
* @param UpdatePirepRequest $request
*
* @return Response
*/
public function update($id, UpdatePirepRequest $request)
{
2017-07-14 11:09:38 +08:00
$pirep = $this->pirepRepo->findWithoutFail($id);
2017-06-29 08:54:05 +08:00
if (empty($pirep)) {
Flash::error('Pirep not found');
return redirect(route('admin.pireps.index'));
}
2017-07-14 11:09:38 +08:00
$pirep = $this->pirepRepo->update($request->all(), $id);
2017-06-29 08:54:05 +08:00
Flash::success('Pirep updated successfully.');
return redirect(route('admin.pireps.index'));
}
/**
* Remove the specified Pirep from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
2017-07-14 11:09:38 +08:00
$pirep = $this->pirepRepo->findWithoutFail($id);
2017-06-29 08:54:05 +08:00
if (empty($pirep)) {
Flash::error('Pirep not found');
return redirect(route('admin.pireps.index'));
}
2017-07-14 11:09:38 +08:00
$this->pirepRepo->delete($id);
2017-06-29 08:54:05 +08:00
Flash::success('Pirep deleted successfully.');
return redirect(route('admin.pireps.index'));
}
}