show all flights in admin/active by default

This commit is contained in:
Nabeel Shahzad 2017-12-26 14:14:04 -06:00
parent 70f1a6ee02
commit 81d349d78d
2 changed files with 11 additions and 5 deletions

View File

@ -54,7 +54,7 @@ class FlightController extends BaseController
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$flights = $this->flightRepo->searchCriteria($request)->paginate(); $flights = $this->flightRepo->searchCriteria($request, false)->paginate();
return view('admin.flights.index', [ return view('admin.flights.index', [
'flights' => $flights, 'flights' => $flights,
'airlines' => $this->airlineRepo->selectBoxList(true), 'airlines' => $this->airlineRepo->selectBoxList(true),
@ -85,6 +85,8 @@ class FlightController extends BaseController
{ {
$input = $request->all(); $input = $request->all();
$input['active'] = true;
$flight = $this->flightRepo->create($input); $flight = $this->flightRepo->create($input);
Flash::success('Flight saved successfully.'); Flash::success('Flight saved successfully.');
@ -148,7 +150,9 @@ class FlightController extends BaseController
return redirect(route('admin.flights.index')); return redirect(route('admin.flights.index'));
} }
$flight = $this->flightRepo->update($request->all(), $id); $attrs = $request->all();
$attrs['active'] = true;
$flight = $this->flightRepo->update($attrs, $id);
Flash::success('Flight updated successfully.'); Flash::success('Flight updated successfully.');
return redirect(route('admin.flights.index')); return redirect(route('admin.flights.index'));

View File

@ -35,9 +35,11 @@ class FlightRepository extends BaseRepository implements CacheableInterface
*/ */
public function searchCriteria(Request $request, bool $only_active=true) public function searchCriteria(Request $request, bool $only_active=true)
{ {
$where = [ $where = [];
'active' => $only_active,
]; if($only_active === true) {
$where['active'] = $only_active;
}
if ($request->filled('flight_id')) { if ($request->filled('flight_id')) {
$where['id'] = $request->flight_id; $where['id'] = $request->flight_id;