repository = $boilerplate; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(BoilerplateUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Boilerplate\Repositories\Criteria\BoilerplateUserCriteria()); $boilerplates = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('boilerplate::boilerplate.names').' :: '); return $this->theme->of('boilerplate::user.boilerplate.index', compact('boilerplates'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Boilerplate $boilerplate * * @return Response */ public function show(BoilerplateUserRequest $request, Boilerplate $boilerplate) { Form::populate($boilerplate); return $this->theme->of('boilerplate::user.boilerplate.show', compact('boilerplate'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(BoilerplateUserRequest $request) { $boilerplate = $this->repository->newInstance([]); Form::populate($boilerplate); return $this->theme->of('boilerplate::user.boilerplate.create', compact('boilerplate'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(BoilerplateUserRequest $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->responseRedirect = trans_url('/user/boilerplate/boilerplate'); 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 Boilerplate $boilerplate * * @return Response */ public function edit(BoilerplateUserRequest $request, Boilerplate $boilerplate) { Form::populate($boilerplate); return $this->theme->of('boilerplate::user.boilerplate.edit', compact('boilerplate'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Boilerplate $boilerplate * * @return Response */ public function update(BoilerplateUserRequest $request, Boilerplate $boilerplate) { try { $this->repository->update($request->all(), $boilerplate->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('boilerplate::boilerplate.name')]); $this->responseRedirect = trans_url('/user/boilerplate/boilerplate'); 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(BoilerplateUserRequest $request, Boilerplate $boilerplate) { try { $this->repository->delete($boilerplate->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('boilerplate::boilerplate.name')]); $this->responseRedirect = trans_url('/user/boilerplate/boilerplate'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }