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