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) { return $this->repository ->setPresenter(\Moblyze\Plan\Repositories\Presenter\PassengerPresenter::class) ->paginate(); } /** * Display passenger. * * @param Request $request * @param Model $passenger * * @return Response */ public function show(PassengerRequest $request, Passenger $passenger) { return $passenger->setPresenter(\Moblyze\Plan\Repositories\Presenter\PassengerListPresenter::class); ; } /** * Create new passenger. * * @param Request $request * * @return Response */ public function store(PassengerRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('plan::passenger.name')]); $code = 204; $status = 'success'; $url = guard_url('plan/passenger/' . $passenger->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('plan/passenger'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the passenger. * * @param Request $request * @param Model $passenger * * @return Response */ public function update(PassengerRequest $request, Passenger $passenger) { try { $data = $request->all(); $passenger->update($data); $message = trans('messages.success.updated', ['Module' => trans('plan::passenger.name')]); $code = 204; $status = 'success'; $url = guard_url('plan/passenger/' . $passenger->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('plan/passenger/' . $passenger->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the passenger. * * @param Model $passenger * * @return Response */ public function destroy(PassengerRequest $request, Passenger $passenger) { try { $passenger->delete(); $message = trans('messages.success.deleted', ['Module' => trans('plan::passenger.name')]); $code = 202; $status = 'success'; $url = guard_url('plan/passenger/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('plan/passenger/' . $passenger->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }