2018-03-21 02:47:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Controller;
|
2018-03-21 02:47:47 +08:00
|
|
|
use App\Repositories\FlightFieldRepository;
|
|
|
|
use Illuminate\Http\Request;
|
2019-12-11 02:53:55 +08:00
|
|
|
use Laracasts\Flash\Flash;
|
2018-03-21 02:47:47 +08:00
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
|
|
|
|
|
|
|
class FlightFieldController extends Controller
|
|
|
|
{
|
|
|
|
private $flightFieldRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FlightFieldController constructor.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @param FlightFieldRepository $flightFieldRepository
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
FlightFieldRepository $flightFieldRepository
|
|
|
|
) {
|
|
|
|
$this->flightFieldRepo = $flightFieldRepository;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the FlightField.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2019-12-11 02:53:55 +08:00
|
|
|
* @return mixed
|
2018-03-21 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->flightFieldRepo->pushCriteria(new RequestCriteria($request));
|
|
|
|
$fields = $this->flightFieldRepo->all();
|
|
|
|
|
|
|
|
return view('admin.flightfields.index', [
|
|
|
|
'fields' => $fields,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new FlightField.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
return view('admin.flightfields.create');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created FlightField in storage.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2019-12-11 02:53:55 +08:00
|
|
|
* @return mixed
|
2018-03-21 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$attrs = $request->all();
|
|
|
|
$attrs['slug'] = str_slug($attrs['name']);
|
|
|
|
|
|
|
|
$this->flightFieldRepo->create($attrs);
|
|
|
|
|
|
|
|
Flash::success('Field added successfully.');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified FlightField.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2019-12-11 02:53:55 +08:00
|
|
|
* @return mixed
|
2018-03-21 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$field = $this->flightFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
|
|
|
Flash::error('Flight field not found');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.flightfields.show', [
|
|
|
|
'field' => $field,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified FlightField.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2019-12-11 02:53:55 +08:00
|
|
|
* @return mixed
|
2018-03-21 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$field = $this->flightFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
|
|
|
Flash::error('Field not found');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('admin.flightfields.edit', [
|
|
|
|
'field' => $field,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified FlightField in storage.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @param $id
|
|
|
|
* @param Request $request
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2018-03-21 02:47:47 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
2019-12-11 02:53:55 +08:00
|
|
|
* @return mixed
|
2018-03-21 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function update($id, Request $request)
|
|
|
|
{
|
|
|
|
$field = $this->flightFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
|
|
|
Flash::error('FlightField not found');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$attrs = $request->all();
|
|
|
|
$attrs['slug'] = str_slug($attrs['name']);
|
|
|
|
$this->flightFieldRepo->update($attrs, $id);
|
|
|
|
|
|
|
|
Flash::success('Field updated successfully.');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified FlightField from storage.
|
2018-08-27 00:40:04 +08:00
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
2019-12-11 02:53:55 +08:00
|
|
|
* @return mixed
|
2018-03-21 02:47:47 +08:00
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$field = $this->flightFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
|
|
|
Flash::error('Field not found');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->flightFieldRepo->delete($id);
|
|
|
|
|
|
|
|
Flash::success('Field deleted successfully.');
|
|
|
|
return redirect(route('admin.flightfields.index'));
|
|
|
|
}
|
|
|
|
}
|