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