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