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