repository = $flight; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Btravel\Flight\Repositories\Criteria\FlightResourceCriteria::class); } /** * Display a list of flight. * * @return Response */ public function index(FlightRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Btravel\Flight\Repositories\Presenter\FlightPresenter::class) ->$function(); } $flights = $this->repository->paginate(); return $this->response->setMetaTitle(trans('flight::flight.names')) ->view('flight::flight.index', true) ->data(compact('flights', 'view')) ->output(); } /** * Display flight. * * @param Request $request * @param Model $flight * * @return Response */ public function show(FlightRequest $request, Flight $flight) { if ($flight->exists) { $view = 'flight::flight.show'; } else { $view = 'flight::flight.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('flight::flight.name')) ->data(compact('flight')) ->view($view, true) ->output(); } /** * Show the form for creating a new flight. * * @param Request $request * * @return Response */ public function create(FlightRequest $request) { $flight = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('flight::flight.name')) ->view('flight::flight.create', true) ->data(compact('flight')) ->output(); } /** * Create new flight. * * @param Request $request * * @return Response */ public function store(FlightRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $flight = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('flight::flight.name')])) ->code(204) ->status('success') ->url(guard_url('flight/flight/' . $flight->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/flight/flight')) ->redirect(); } } /** * Show flight for editing. * * @param Request $request * @param Model $flight * * @return Response */ public function edit(FlightRequest $request, Flight $flight) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('flight::flight.name')) ->view('flight::flight.edit', true) ->data(compact('flight')) ->output(); } /** * Update the flight. * * @param Request $request * @param Model $flight * * @return Response */ public function update(FlightRequest $request, Flight $flight) { try { $attributes = $request->all(); $flight->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('flight::flight.name')])) ->code(204) ->status('success') ->url(guard_url('flight/flight/' . $flight->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('flight/flight/' . $flight->getRouteKey())) ->redirect(); } } /** * Remove the flight. * * @param Model $flight * * @return Response */ public function destroy(FlightRequest $request, Flight $flight) { try { $flight->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('flight::flight.name')])) ->code(202) ->status('success') ->url(guard_url('flight/flight/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('flight/flight/' . $flight->getRouteKey())) ->redirect(); } } /** * Remove multiple flight. * * @param Model $flight * * @return Response */ public function delete(FlightRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('flight::flight.name')])) ->status("success") ->code(202) ->url(guard_url('flight/flight')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/flight/flight')) ->redirect(); } } /** * Restore deleted flights. * * @param Model $flight * * @return Response */ public function restore(FlightRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('flight::flight.name')])) ->status("success") ->code(202) ->url(guard_url('/flight/flight')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/flight/flight/')) ->redirect(); } } }