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