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