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