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