2017-06-29 08:54:05 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Requests\CreatePirepFieldRequest;
|
|
|
|
use App\Http\Requests\UpdatePirepFieldRequest;
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Controller;
|
2017-06-29 08:54:05 +08:00
|
|
|
use App\Repositories\PirepFieldRepository;
|
|
|
|
use Flash;
|
2018-02-21 12:33:09 +08:00
|
|
|
use Illuminate\Http\Request;
|
2017-06-29 08:54:05 +08:00
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
|
|
|
use Response;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class PirepFieldController
|
|
|
|
* @package App\Http\Controllers\Admin
|
|
|
|
*/
|
|
|
|
class PirepFieldController extends Controller
|
2017-06-29 08:54:05 +08:00
|
|
|
{
|
|
|
|
private $pirepFieldRepo;
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* PirepFieldController constructor.
|
|
|
|
* @param PirepFieldRepository $pirepFieldRepo
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
PirepFieldRepository $pirepFieldRepo
|
2018-03-20 09:50:40 +08:00
|
|
|
) {
|
2017-06-29 08:54:05 +08:00
|
|
|
$this->pirepFieldRepo = $pirepFieldRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the PirepField.
|
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2018-01-24 05:48:30 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->pirepFieldRepo->pushCriteria(new RequestCriteria($request));
|
|
|
|
$fields = $this->pirepFieldRepo->all();
|
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return view('admin.pirepfields.index', [
|
2017-06-29 08:54:05 +08:00
|
|
|
'fields' => $fields,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new PirepField.
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2018-01-01 04:20:52 +08:00
|
|
|
return view('admin.pirepfields.create');
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created PirepField in storage.
|
|
|
|
* @param CreatePirepFieldRequest $request
|
|
|
|
* @return Response
|
2018-01-22 02:43:32 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function store(CreatePirepFieldRequest $request)
|
|
|
|
{
|
2018-02-07 00:02:34 +08:00
|
|
|
$attrs = $request->all();
|
|
|
|
$attrs['slug'] = str_slug($attrs['name']);
|
|
|
|
$attrs['required'] = get_truth_state($attrs['required']);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-02-07 00:02:34 +08:00
|
|
|
$this->pirepFieldRepo->create($attrs);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
Flash::success('Field added successfully.');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified PirepField.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$field = $this->pirepFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
|
|
|
Flash::error('PirepField not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return view('admin.pirepfields.show', [
|
2017-06-29 08:54:05 +08:00
|
|
|
'field' => $field,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified PirepField.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$field = $this->pirepFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
2018-02-21 12:33:09 +08:00
|
|
|
Flash::error('Field not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return view('admin.pirepfields.edit', [
|
2017-06-29 08:54:05 +08:00
|
|
|
'field' => $field,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified PirepField in storage.
|
2018-01-22 02:43:32 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2017-06-29 08:54:05 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdatePirepFieldRequest $request)
|
|
|
|
{
|
|
|
|
$field = $this->pirepFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
|
|
|
Flash::error('PirepField not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
2018-01-22 02:43:32 +08:00
|
|
|
$attrs = $request->all();
|
2018-02-07 00:02:34 +08:00
|
|
|
$attrs['slug'] = str_slug($attrs['name']);
|
2018-01-22 02:43:32 +08:00
|
|
|
$attrs['required'] = get_truth_state($attrs['required']);
|
|
|
|
$this->pirepFieldRepo->update($attrs, $id);
|
2017-06-29 08:54:05 +08:00
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
Flash::success('Field updated successfully.');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified PirepField from storage.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$field = $this->pirepFieldRepo->findWithoutFail($id);
|
|
|
|
|
|
|
|
if (empty($field)) {
|
2018-02-21 12:33:09 +08:00
|
|
|
Flash::error('Field not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->pirepFieldRepo->delete($id);
|
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
Flash::success('Field deleted successfully.');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-01 04:20:52 +08:00
|
|
|
return redirect(route('admin.pirepfields.index'));
|
2017-06-29 08:54:05 +08:00
|
|
|
}
|
|
|
|
}
|