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) { return $this->repository ->setPresenter(\Btravel\Object\Repositories\Presenter\ObjectPresenter::class) ->paginate(); } /** * Display object. * * @param Request $request * @param Model $object * * @return Response */ public function show(ObjectRequest $request, Object $object) { return $object->setPresenter(\Btravel\Object\Repositories\Presenter\ObjectListPresenter::class); ; } /** * Create new object. * * @param Request $request * * @return Response */ public function store(ObjectRequest $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::object.name')]); $code = 204; $status = 'success'; $url = guard_url('object/object/' . $object->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('object/object'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the object. * * @param Request $request * @param Model $object * * @return Response */ public function update(ObjectRequest $request, Object $object) { try { $data = $request->all(); $object->update($data); $message = trans('messages.success.updated', ['Module' => trans('object::object.name')]); $code = 204; $status = 'success'; $url = guard_url('object/object/' . $object->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('object/object/' . $object->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the object. * * @param Model $object * * @return Response */ public function destroy(ObjectRequest $request, Object $object) { try { $object->delete(); $message = trans('messages.success.deleted', ['Module' => trans('object::object.name')]); $code = 202; $status = 'success'; $url = guard_url('object/object/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('object/object/' . $object->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); } }