repository = $object; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Btravel\Objects\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\Objects\Repositories\Presenter\ObjectPresenter::class) ->$function(); } $objects = $this->repository->paginate(); return $this->response->setMetaTitle(trans('objects::object.names')) ->view('objects::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 = 'objects::object.show'; } else { $view = 'objects::object.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('objects::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('objects::object.name')) ->view('objects::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('objects::object.name')])) ->code(204) ->status('success') ->url(guard_url('objects/object/' . $object->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/objects/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('objects::object.name')) ->view('objects::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('objects::object.name')])) ->code(204) ->status('success') ->url(guard_url('objects/object/' . $object->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('objects/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('objects::object.name')])) ->code(202) ->status('success') ->url(guard_url('objects/object/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('objects/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('objects::object.name')])) ->status("success") ->code(202) ->url(guard_url('objects/object')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/objects/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('objects::object.name')])) ->status("success") ->code(202) ->url(guard_url('/objects/object')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/objects/object/')) ->redirect(); } } }