repository = $objects; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Ebuy\Object\Repositories\Criteria\ObjectsResourceCriteria::class); } /** * Display a list of objects. * * @return Response */ public function index(ObjectsRequest $request) { return $this->repository ->setPresenter(\Ebuy\Object\Repositories\Presenter\ObjectsPresenter::class) ->paginate(); } /** * Display objects. * * @param Request $request * @param Model $objects * * @return Response */ public function show(ObjectsRequest $request, Objects $objects) { return $objects->setPresenter(\Ebuy\Object\Repositories\Presenter\ObjectsListPresenter::class); ; } /** * Create new objects. * * @param Request $request * * @return Response */ public function store(ObjectsRequest $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('object::objects.name')]); $code = 204; $status = 'success'; $url = guard_url('object/objects/' . $objects->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('object/objects'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the objects. * * @param Request $request * @param Model $objects * * @return Response */ public function update(ObjectsRequest $request, Objects $objects) { try { $data = $request->all(); $objects->update($data); $message = trans('messages.success.updated', ['Module' => trans('object::objects.name')]); $code = 204; $status = 'success'; $url = guard_url('object/objects/' . $objects->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('object/objects/' . $objects->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the objects. * * @param Model $objects * * @return Response */ public function destroy(ObjectsRequest $request, Objects $objects) { try { $objects->delete(); $message = trans('messages.success.deleted', ['Module' => trans('object::objects.name')]); $code = 202; $status = 'success'; $url = guard_url('object/objects/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('object/objects/' . $objects->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); } }