repository = $associations; parent::__construct(); } /** * Display a list of associations. * * @return json */ public function index(AssociationsRequest $request) { $associations = $this->repository ->setPresenter('\\Nico\\Nico\\Repositories\\Presenter\\AssociationsListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); $associations['code'] = 2000; return response()->json($associations) ->setStatusCode(200, 'INDEX_SUCCESS'); } /** * Display associations. * * @param Request $request * @param Model Associations * * @return Json */ public function show(AssociationsRequest $request, Associations $associations) { $associations = $associations->presenter(); $associations['code'] = 2001; return response()->json($associations) ->setStatusCode(200, 'SHOW_SUCCESS');; } /** * Show the form for creating a new associations. * * @param Request $request * * @return json */ public function create(AssociationsRequest $request, Associations $associations) { $associations = $associations->presenter(); $associations['code'] = 2002; return response()->json($associations) ->setStatusCode(200, 'CREATE_SUCCESS'); } /** * Create new associations. * * @param Request $request * * @return json */ public function store(AssociationsRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.api'); $associations = $this->repository->create($attributes); $associations = $associations->presenter(); $associations['code'] = 2004; return response()->json($associations) ->setStatusCode(201, 'STORE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4004, ])->setStatusCode(400, 'STORE_ERROR'); } } /** * Show associations for editing. * * @param Request $request * @param Model $associations * * @return json */ public function edit(AssociationsRequest $request, Associations $associations) { $associations = $associations->presenter(); $associations['code'] = 2003; return response()-> json($associations) ->setStatusCode(200, 'EDIT_SUCCESS');; } /** * Update the associations. * * @param Request $request * @param Model $associations * * @return json */ public function update(AssociationsRequest $request, Associations $associations) { try { $attributes = $request->all(); $associations->update($attributes); $associations = $associations->presenter(); $associations['code'] = 2005; return response()->json($associations) ->setStatusCode(201, 'UPDATE_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4005, ])->setStatusCode(400, 'UPDATE_ERROR'); } } /** * Remove the associations. * * @param Request $request * @param Model $associations * * @return json */ public function destroy(AssociationsRequest $request, Associations $associations) { try { $t = $associations->delete(); return response()->json([ 'message' => trans('messages.success.delete', ['Module' => trans('nico::associations.name')]), 'code' => 2006 ])->setStatusCode(202, 'DESTROY_SUCCESS'); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 4006, ])->setStatusCode(400, 'DESTROY_ERROR'); } } }