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