repository = $forms; } /** * Display a list of forms. * * @return Response */ public function index(FormsAdminRequest $request) { $forms = $this->repository->setPresenter('\\Moamen\\Business\\Repositories\\Presenter\\FormsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('business::forms.names').' :: '); $view = $this->theme->of('business::admin.forms.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('business::forms.name')]); $this->responseData = $forms['data']; $this->responseMeta = $forms['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display forms. * * @param Request $request * @param int $id * * @return Response */ public function show(FormsAdminRequest $request, Forms $forms) { if (!$forms->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('business::forms.name')]); $this->responseView = view('business::admin.forms.new'); return $this -> respond($request); } Form::populate($forms); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('business::forms.name')]); $this->responseData = $forms; $this->responseView = view('business::admin.forms.show', compact('forms')); return $this -> respond($request); } /** * Show the form for creating a new forms. * * @param Request $request * * @return Response */ public function create(FormsAdminRequest $request) { $forms = $this->repository->newInstance([]); Form::populate($forms); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('business::forms.name')]); $this->responseData = $forms; $this->responseView = view('business::admin.forms.create', compact('forms')); return $this -> respond($request); } /** * Create new forms. * * @param Request $request * * @return Response */ public function store(FormsAdminRequest $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->responseData = $forms; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/business/forms/'.$forms->getRouteKey()); $this->responseView = view('business::admin.forms.create', compact('forms')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show forms for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(FormsAdminRequest $request, Forms $forms) { Form::populate($forms); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('business::forms.name')]); $this->responseData = $forms; $this->responseView = view('business::admin.forms.edit', compact('forms')); return $this -> respond($request); } /** * Update the forms. * * @param Request $request * @param int $id * * @return Response */ public function update(FormsAdminRequest $request, Forms $forms) { try { $attributes = $request->all(); $forms->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('business::forms.name')]); $this->responseData = $forms; $this->responseRedirect = trans_url('/admin/business/forms/'.$forms->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/business/forms/'.$forms->getRouteKey()); return $this -> respond($request); } } /** * Remove the forms. * * @param int $id * * @return Response */ public function destroy(FormsAdminRequest $request, Forms $forms) { try { $t = $forms->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('business::forms.name')]); $this->responseRedirect = trans_url('/admin/business/forms/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/business/forms/'.$forms->getRouteKey()); return $this -> respond($request); } } }