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