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