repository = $medicine; } /** * Display a list of medicine. * * @return Response */ public function index(MedicineAdminRequest $request) { $medicines = $this->repository->setPresenter('\\Test123\\Test123\\Repositories\\Presenter\\MedicineListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('test123::medicine.names').' :: '); $view = $this->theme->of('test123::admin.medicine.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('test123::medicine.name')]); $this->responseData = $medicines['data']; $this->responseMeta = $medicines['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display medicine. * * @param Request $request * @param int $id * * @return Response */ public function show(MedicineAdminRequest $request, Medicine $medicine) { if (!$medicine->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('test123::medicine.name')]); $this->responseView = view('test123::admin.medicine.new'); return $this -> respond($request); } Form::populate($medicine); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('test123::medicine.name')]); $this->responseData = $medicine; $this->responseView = view('test123::admin.medicine.show', compact('medicine')); return $this -> respond($request); } /** * Show the form for creating a new medicine. * * @param Request $request * * @return Response */ public function create(MedicineAdminRequest $request) { $medicine = $this->repository->newInstance([]); Form::populate($medicine); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('test123::medicine.name')]); $this->responseData = $medicine; $this->responseView = view('test123::admin.medicine.create', compact('medicine')); return $this -> respond($request); } /** * Create new medicine. * * @param Request $request * * @return Response */ public function store(MedicineAdminRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $medicine = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('test123::medicine.name')]); $this->responseData = $medicine; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/test123/medicine/'.$medicine->getRouteKey()); $this->responseView = view('test123::admin.medicine.create', compact('medicine')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show medicine for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(MedicineAdminRequest $request, Medicine $medicine) { Form::populate($medicine); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('test123::medicine.name')]); $this->responseData = $medicine; $this->responseView = view('test123::admin.medicine.edit', compact('medicine')); return $this -> respond($request); } /** * Update the medicine. * * @param Request $request * @param int $id * * @return Response */ public function update(MedicineAdminRequest $request, Medicine $medicine) { try { $attributes = $request->all(); $medicine->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('test123::medicine.name')]); $this->responseData = $medicine; $this->responseRedirect = trans_url('/admin/test123/medicine/'.$medicine->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/test123/medicine/'.$medicine->getRouteKey()); return $this -> respond($request); } } /** * Remove the medicine. * * @param int $id * * @return Response */ public function destroy(MedicineAdminRequest $request, Medicine $medicine) { try { $t = $medicine->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('test123::medicine.name')]); $this->responseRedirect = trans_url('/admin/test123/medicine/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/test123/medicine/'.$medicine->getRouteKey()); return $this -> respond($request); } } }