Skip to content

Commit

Permalink
API: Flight fields are an array when empty #618 (#619)
Browse files Browse the repository at this point in the history
* Ensure 'fields' field is return as an object for flights #618
* Eager loading for flight fields
  • Loading branch information
nabeelio committed Mar 4, 2020
1 parent 174b602 commit 9ed2e3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/Http/Controllers/Api/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ public function search(Request $request)
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
$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) {
return response($e, 503);
}
Expand Down
11 changes: 9 additions & 2 deletions app/Http/Resources/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
namespace App\Http\Resources;

use App\Support\Units\Distance;
use stdClass;

class Flight extends Response
{
/**
* Set the fields on the flight object
*
* @return array
* @mixin \App\Models\Flight
*/
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 = [];
foreach ($this->field_values as $field) {
foreach ($field_values as $field) {
$fields[$field->name] = $field->value;
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/flights/fields.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class="required">*</span>
<div class="checkbox">
<label class="checkbox-inline">
{{ Form::label('active', 'Active:') }}
{{ Form::hidden('active', 0, false) }}
<input name="active" type="hidden" value="0" />
{{ Form::checkbox('active') }}
</label>
</div>
Expand Down

0 comments on commit 9ed2e3f

Please sign in to comment.