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