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