repository = $associations; parent::__construct(); } /** * Display a list of associations. * * @return Response */ public function index(AssociationsRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('nico::associations.names').' :: '); return $this->theme->of('nico::admin.associations.index')->render(); } /** * Display a list of associations. * * @return Response */ public function getJson(AssociationsRequest $request) { $pageLimit = $request->input('pageLimit'); $associations = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Nico\\Nico\\Repositories\\Presenter\\AssociationsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $associations['recordsTotal'] = $associations['meta']['pagination']['total']; $associations['recordsFiltered'] = $associations['meta']['pagination']['total']; $associations['request'] = $request->all(); return response()->json($associations, 200); } /** * Display associations. * * @param Request $request * @param Model $associations * * @return Response */ public function show(AssociationsRequest $request, Associations $associations) { if (!$associations->exists) { return response()->view('nico::admin.associations.new', compact('associations')); } Form::populate($associations); return response()->view('nico::admin.associations.show', compact('associations')); } /** * Show the form for creating a new associations. * * @param Request $request * * @return Response */ public function create(AssociationsRequest $request) { $associations = $this->repository->newInstance([]); Form::populate($associations); return response()->view('nico::admin.associations.create', compact('associations')); } /** * Create new associations. * * @param Request $request * * @return Response */ public function store(AssociationsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $associations = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('nico::associations.name')]), 'code' => 204, 'redirect' => trans_url('/admin/nico/associations/'.$associations->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show associations for editing. * * @param Request $request * @param Model $associations * * @return Response */ public function edit(AssociationsRequest $request, Associations $associations) { Form::populate($associations); return response()->view('nico::admin.associations.edit', compact('associations')); } /** * Update the associations. * * @param Request $request * @param Model $associations * * @return Response */ public function update(AssociationsRequest $request, Associations $associations) { try { $attributes = $request->all(); $associations->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('nico::associations.name')]), 'code' => 204, 'redirect' => trans_url('/admin/nico/associations/'.$associations->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/nico/associations/'.$associations->getRouteKey()), ], 400); } } /** * Remove the associations. * * @param Model $associations * * @return Response */ public function destroy(AssociationsRequest $request, Associations $associations) { try { $t = $associations->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('nico::associations.name')]), 'code' => 202, 'redirect' => trans_url('/admin/nico/associations/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/nico/associations/'.$associations->getRouteKey()), ], 400); } } }