* Ensure 'fields' field is return as an object for flights #618 * Eager loading for flight fields
This commit is contained in:
parent
174b602d7c
commit
9ed2e3f9f4
@ -88,7 +88,15 @@ class FlightController extends Controller
|
|||||||
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
|
||||||
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
||||||
|
|
||||||
$flights = $this->flightRepo->paginate();
|
$flights = $this->flightRepo
|
||||||
|
->with([
|
||||||
|
'airline',
|
||||||
|
'subfleets',
|
||||||
|
'subfleets.aircraft',
|
||||||
|
'subfleets.fares',
|
||||||
|
'field_values',
|
||||||
|
])
|
||||||
|
->paginate();
|
||||||
} catch (RepositoryException $e) {
|
} catch (RepositoryException $e) {
|
||||||
return response($e, 503);
|
return response($e, 503);
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,25 @@
|
|||||||
namespace App\Http\Resources;
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
use App\Support\Units\Distance;
|
use App\Support\Units\Distance;
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
class Flight extends Response
|
class Flight extends Response
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Set the fields on the flight object
|
* Set the fields on the flight object
|
||||||
*
|
*
|
||||||
* @return array
|
* @mixin \App\Models\Flight
|
||||||
*/
|
*/
|
||||||
private function setFields()
|
private function setFields()
|
||||||
{
|
{
|
||||||
|
/** @var \Illuminate\Support\Collection $field_values */
|
||||||
|
$field_values = $this->field_values;
|
||||||
|
if (empty($field_values) || $field_values->count() === 0) {
|
||||||
|
return new stdClass();
|
||||||
|
}
|
||||||
|
|
||||||
$fields = [];
|
$fields = [];
|
||||||
foreach ($this->field_values as $field) {
|
foreach ($field_values as $field) {
|
||||||
$fields[$field->name] = $field->value;
|
$fields[$field->name] = $field->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@
|
|||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label class="checkbox-inline">
|
<label class="checkbox-inline">
|
||||||
{{ Form::label('active', 'Active:') }}
|
{{ Form::label('active', 'Active:') }}
|
||||||
{{ Form::hidden('active', 0, false) }}
|
<input name="active" type="hidden" value="0" />
|
||||||
{{ Form::checkbox('active') }}
|
{{ Form::checkbox('active') }}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user