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