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