repository = $appointment; parent::__construct(); } /** * Display a list of appointment. * * @return Response */ public function index(AppointmentRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('appointment::appointment.names').' :: '); return $this->theme->of('appointment::admin.appointment.index')->render(); } /** * Display a list of appointment. * * @return Response */ public function getJson(AppointmentRequest $request) { $pageLimit = $request->input('pageLimit'); $appointments = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Vmc\\Appointment\\Repositories\\Presenter\\AppointmentListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $appointments['recordsTotal'] = $appointments['meta']['pagination']['total']; $appointments['recordsFiltered'] = $appointments['meta']['pagination']['total']; $appointments['request'] = $request->all(); return response()->json($appointments, 200); } /** * Display appointment. * * @param Request $request * @param Model $appointment * * @return Response */ public function show(AppointmentRequest $request, Appointment $appointment) { if (!$appointment->exists) { return response()->view('appointment::admin.appointment.new', compact('appointment')); } Form::populate($appointment); return response()->view('appointment::admin.appointment.show', compact('appointment')); } /** * Show the form for creating a new appointment. * * @param Request $request * * @return Response */ public function create(AppointmentRequest $request) { $appointment = $this->repository->newInstance([]); Form::populate($appointment); return response()->view('appointment::admin.appointment.create', compact('appointment')); } /** * Create new appointment. * * @param Request $request * * @return Response */ public function store(AppointmentRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $appointment = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('appointment::appointment.name')]), 'code' => 204, 'redirect' => trans_url('/admin/appointment/appointment/'.$appointment->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show appointment for editing. * * @param Request $request * @param Model $appointment * * @return Response */ public function edit(AppointmentRequest $request, Appointment $appointment) { Form::populate($appointment); return response()->view('appointment::admin.appointment.edit', compact('appointment')); } /** * Update the appointment. * * @param Request $request * @param Model $appointment * * @return Response */ public function update(AppointmentRequest $request, Appointment $appointment) { try { $attributes = $request->all(); $appointment->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('appointment::appointment.name')]), 'code' => 204, 'redirect' => trans_url('/admin/appointment/appointment/'.$appointment->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/appointment/appointment/'.$appointment->getRouteKey()), ], 400); } } /** * Remove the appointment. * * @param Model $appointment * * @return Response */ public function destroy(AppointmentRequest $request, Appointment $appointment) { try { $t = $appointment->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('appointment::appointment.name')]), 'code' => 202, 'redirect' => trans_url('/admin/appointment/appointment/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/appointment/appointment/'.$appointment->getRouteKey()), ], 400); } } }