cleaned searching for flights, specific fields in admin
This commit is contained in:
@@ -11,6 +11,7 @@ use App\Repositories\AirlineRepository;
|
|||||||
use App\Repositories\AirportRepository;
|
use App\Repositories\AirportRepository;
|
||||||
use App\Repositories\FlightRepository;
|
use App\Repositories\FlightRepository;
|
||||||
use App\Repositories\SubfleetRepository;
|
use App\Repositories\SubfleetRepository;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Flash;
|
use Flash;
|
||||||
use Prettus\Repository\Criteria\RequestCriteria;
|
use Prettus\Repository\Criteria\RequestCriteria;
|
||||||
@@ -57,10 +58,11 @@ class FlightController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->flightRepo->pushCriteria(new RequestCriteria($request));
|
$flights = $this->flightRepo->searchCriteria($request)->paginate();
|
||||||
$flights = $this->flightRepo->paginate(10);
|
|
||||||
return view('admin.flights.index', [
|
return view('admin.flights.index', [
|
||||||
'flights' => $flights,
|
'flights' => $flights,
|
||||||
|
'airlines' => $this->airlineRepo->selectBoxList(true),
|
||||||
|
'airports' => $this->airportRepo->selectBoxList(true),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,15 @@ class AirlineRepository extends BaseRepository implements CacheableInterface
|
|||||||
* Return the list of airline formatted for a select box
|
* Return the list of airline formatted for a select box
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function selectBoxList(): array
|
public function selectBoxList($add_blank=false): array
|
||||||
{
|
{
|
||||||
$retval = [];
|
$retval = [];
|
||||||
$items = $this->all();
|
$items = $this->all();
|
||||||
|
|
||||||
|
if($add_blank) {
|
||||||
|
$retval[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($items as $i) {
|
foreach ($items as $i) {
|
||||||
$retval[$i->id] = $i->name;
|
$retval[$i->id] = $i->name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,10 +25,15 @@ class AirportRepository extends BaseRepository implements CacheableInterface
|
|||||||
* Return the list of airports formatted for a select box
|
* Return the list of airports formatted for a select box
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function selectBoxList(): array
|
public function selectBoxList($add_blank=false): array
|
||||||
{
|
{
|
||||||
$retval = [];
|
$retval = [];
|
||||||
$items = $this->all();
|
$items = $this->all();
|
||||||
|
|
||||||
|
if ($add_blank) {
|
||||||
|
$retval[''] = '';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($items as $i) {
|
foreach ($items as $i) {
|
||||||
$retval[$i->icao] = $i->icao . ' - ' . $i->name;
|
$retval[$i->icao] = $i->icao . ' - ' . $i->name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Repositories;
|
|||||||
|
|
||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
use App\Repositories\Criteria\WhereCriteria;
|
use App\Repositories\Criteria\WhereCriteria;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Prettus\Repository\Contracts\CacheableInterface;
|
use Prettus\Repository\Contracts\CacheableInterface;
|
||||||
use Prettus\Repository\Traits\CacheableRepository;
|
use Prettus\Repository\Traits\CacheableRepository;
|
||||||
@@ -27,7 +28,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the search criteria and return this with the stuff pushed
|
* Create the search criteria and return this with the stuff pushed
|
||||||
* @param Request $request
|
* @param FormRequest $request
|
||||||
* @param bool $only_active
|
* @param bool $only_active
|
||||||
* @return $this
|
* @return $this
|
||||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||||
@@ -38,16 +39,24 @@ class FlightRepository extends BaseRepository implements CacheableInterface
|
|||||||
'active' => $only_active,
|
'active' => $only_active,
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($request->airline) {
|
if ($request->filled('airline_id')) {
|
||||||
$where['airline_id'] = $request->airline;
|
$where['airline_id'] = $request->airline_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->depICAO) {
|
if($request->filled('flight_number')) {
|
||||||
$where['dpt_airport_id'] = $request->depICAO;
|
$where['flight_number'] = $request->flight_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->arrICAO) {
|
if ($request->filled('route_code')) {
|
||||||
$where['dpt_airport_id'] = $request->arrICAO;
|
$where['route_code'] = $request->route_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('dep_icao')) {
|
||||||
|
$where['dpt_airport_id'] = $request->dep_icao;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('arr_icao')) {
|
||||||
|
$where['arr_airport_id'] = $request->arr_icao;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->pushCriteria(new WhereCriteria($request, $where));
|
$this->pushCriteria(new WhereCriteria($request, $where));
|
||||||
|
|||||||
@@ -3,9 +3,19 @@
|
|||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::open(['route' => 'admin.flights.index', 'method' => 'GET', 'class'=>'form-inline pull-right']) !!}
|
{!! Form::open(['route' => 'admin.flights.index', 'method' => 'GET', 'class'=>'form-inline pull-right']) !!}
|
||||||
{!! Form::label('search', 'search:') !!}
|
|
||||||
{!! Form::text('search', null, ['class' => 'form-control']) !!}
|
{!! Form::label('flight_number', 'Flight Number:') !!}
|
||||||
|
{!! Form::text('flight_number', null, ['class' => 'form-control']) !!}
|
||||||
|
|
||||||
|
{!! Form::label('dep_icao', 'Departure:') !!}
|
||||||
|
{!! Form::select('dep_icao', $airports, null , ['class' => 'form-control']) !!}
|
||||||
|
|
||||||
|
{!! Form::label('arr_icao', 'Arrival:') !!}
|
||||||
|
{!! Form::select('arr_icao', $airports, null , ['class' => 'form-control']) !!}
|
||||||
|
|
||||||
{!! Form::submit('find', ['class' => 'btn btn-primary']) !!}
|
{!! Form::submit('find', ['class' => 'btn btn-primary']) !!}
|
||||||
|
|
||||||
|
<a href="{!! route('admin.flights.index') !!}">clear</a>
|
||||||
{!! Form::close() !!}
|
{!! Form::close() !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user