repository = $medicine; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(MedicineUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Test123\Repositories\Criteria\MedicineUserCriteria()); $medicines = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('test123::medicine.names').' :: '); return $this->theme->of('test123::user.medicine.index', compact('medicines'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Medicine $medicine * * @return Response */ public function show(MedicineUserRequest $request, Medicine $medicine) { Form::populate($medicine); return $this->theme->of('test123::user.medicine.show', compact('medicine'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(MedicineUserRequest $request) { $medicine = $this->repository->newInstance([]); Form::populate($medicine); return $this->theme->of('test123::user.medicine.create', compact('medicine'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(MedicineUserRequest $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->responseRedirect = trans_url('/user/test123/medicine'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Medicine $medicine * * @return Response */ public function edit(MedicineUserRequest $request, Medicine $medicine) { Form::populate($medicine); return $this->theme->of('test123::user.medicine.edit', compact('medicine'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Medicine $medicine * * @return Response */ public function update(MedicineUserRequest $request, Medicine $medicine) { try { $this->repository->update($request->all(), $medicine->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('test123::medicine.name')]); $this->responseRedirect = trans_url('/user/test123/medicine'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(MedicineUserRequest $request, Medicine $medicine) { try { $this->repository->delete($medicine->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('test123::medicine.name')]); $this->responseRedirect = trans_url('/user/test123/medicine'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }