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