repository = $forms; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(FormsUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Business\Repositories\Criteria\FormsUserCriteria()); $forms = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('business::forms.names').' :: '); return $this->theme->of('business::user.forms.index', compact('forms'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Forms $forms * * @return Response */ public function show(FormsUserRequest $request, Forms $forms) { Form::populate($forms); return $this->theme->of('business::user.forms.show', compact('forms'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(FormsUserRequest $request) { $forms = $this->repository->newInstance([]); Form::populate($forms); return $this->theme->of('business::user.forms.create', compact('forms'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(FormsUserRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $forms = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('business::forms.name')]); $this->responseRedirect = trans_url('/user/business/forms'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Forms $forms * * @return Response */ public function edit(FormsUserRequest $request, Forms $forms) { Form::populate($forms); return $this->theme->of('business::user.forms.edit', compact('forms'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Forms $forms * * @return Response */ public function update(FormsUserRequest $request, Forms $forms) { try { $this->repository->update($request->all(), $forms->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('business::forms.name')]); $this->responseRedirect = trans_url('/user/business/forms'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(FormsUserRequest $request, Forms $forms) { try { $this->repository->delete($forms->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('business::forms.name')]); $this->responseRedirect = trans_url('/user/business/forms'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }