Cast the required field properly and add helper #146
This commit is contained in:
parent
e86fd64235
commit
f09b3b888a
@ -18,13 +18,6 @@ class AirportController extends BaseController
|
||||
/** @var AirportRepository */
|
||||
private $airportRepository;
|
||||
|
||||
public static $enabledStates = [
|
||||
'on',
|
||||
'true',
|
||||
'1',
|
||||
true,
|
||||
];
|
||||
|
||||
public function __construct(AirportRepository $airportRepo)
|
||||
{
|
||||
$this->airportRepository = $airportRepo;
|
||||
@ -73,7 +66,7 @@ class AirportController extends BaseController
|
||||
public function store(CreateAirportRequest $request)
|
||||
{
|
||||
$input = $request->all();
|
||||
$input['hub'] = \in_array($input['hub'], self::$enabledStates);
|
||||
$input['hub'] = get_truth_state($input['hub']);
|
||||
|
||||
$this->airportRepository->create($input);
|
||||
|
||||
@ -137,7 +130,7 @@ class AirportController extends BaseController
|
||||
}
|
||||
|
||||
$attrs = $request->all();
|
||||
$attrs['hub'] = \in_array($attrs['hub'], self::$enabledStates);
|
||||
$attrs['hub'] = get_truth_state($attrs['hub']);
|
||||
|
||||
$this->airportRepository->update($attrs, $id);
|
||||
|
||||
|
@ -52,12 +52,14 @@ class PirepFieldController extends BaseController
|
||||
* @param CreatePirepFieldRequest $request
|
||||
*
|
||||
* @return Response
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function store(CreatePirepFieldRequest $request)
|
||||
{
|
||||
$input = $request->all();
|
||||
$input['required'] = get_truth_state($input['required']);
|
||||
|
||||
$field = $this->pirepFieldRepo->create($input);
|
||||
$this->pirepFieldRepo->create($input);
|
||||
|
||||
Flash::success('PirepField saved successfully.');
|
||||
return redirect(route('admin.pirepfields.index'));
|
||||
@ -107,6 +109,7 @@ class PirepFieldController extends BaseController
|
||||
|
||||
/**
|
||||
* Update the specified PirepField in storage.
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function update($id, UpdatePirepFieldRequest $request)
|
||||
{
|
||||
@ -117,7 +120,9 @@ class PirepFieldController extends BaseController
|
||||
return redirect(route('admin.pirepfields.index'));
|
||||
}
|
||||
|
||||
$field = $this->pirepFieldRepo->update($request->all(), $id);
|
||||
$attrs = $request->all();
|
||||
$attrs['required'] = get_truth_state($attrs['required']);
|
||||
$this->pirepFieldRepo->update($attrs, $id);
|
||||
|
||||
Flash::success('PirepField updated successfully.');
|
||||
return redirect(route('admin.pirepfields.index'));
|
||||
|
@ -1,5 +1,25 @@
|
||||
<?php
|
||||
|
||||
if(!function_exists('get_truth_state')) {
|
||||
/**
|
||||
* Check if the passed state matches any of the states that
|
||||
* we regard as being true or false
|
||||
* @param $state
|
||||
* @return bool
|
||||
*/
|
||||
function get_truth_state($state)
|
||||
{
|
||||
$enabledStates = [
|
||||
'on',
|
||||
'true',
|
||||
'1',
|
||||
true,
|
||||
];
|
||||
|
||||
return \in_array($state, $enabledStates, false);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('list_to_assoc')) {
|
||||
/**
|
||||
* Converts a straight list into an assoc array with
|
||||
|
Loading…
Reference in New Issue
Block a user