middleware(function ($request, $next) { $this->form = AppointmentForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('prajna.appointment.modules'), 'appointment', guard_url('appointment')); return $next($request); }); } /** * Display a list of appointment. * * @return Response */ public function index(AppointmentResourceRequest $request) { $request = $request->all(); $page = AppointmentActions::run('paginate', $request); $data = new AppointmentsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('appointment::appointment.names')) ->view('appointment::appointment.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display appointment. * * @param Request $request * @param Model $appointment * * @return Response */ public function show(AppointmentResourceRequest $request, Appointment $model) { $form = $this->form; $modules = $this->modules; $data = new AppointmentResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('appointment::appointment.name')) ->data(compact('data', 'form', 'modules')) ->view('appointment::appointment.show') ->output(); } /** * Show the form for creating a new appointment. * * @param Request $request * * @return Response */ public function create(AppointmentResourceRequest $request, Appointment $model) { $form = $this->form; $modules = $this->modules; $data = new AppointmentResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('appointment::appointment.name')) ->view('appointment::appointment.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new appointment. * * @param Request $request * * @return Response */ public function store(AppointmentResourceRequest $request, Appointment $model) { try { $request = $request->all(); $model = AppointmentAction::run('store', $model, $request); $data = new AppointmentResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('appointment::appointment.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('appointment/appointment/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/appointment/appointment')) ->redirect(); } } /** * Show appointment for editing. * * @param Request $request * @param Model $appointment * * @return Response */ public function edit(AppointmentResourceRequest $request, Appointment $model) { $form = $this->form; $modules = $this->modules; $data = new AppointmentResource($model); // return view('appointment::appointment.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('appointment::appointment.name')) ->view('appointment::appointment.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the appointment. * * @param Request $request * @param Model $appointment * * @return Response */ public function update(AppointmentResourceRequest $request, Appointment $model) { try { $request = $request->all(); $model = AppointmentAction::run('update', $model, $request); $data = new AppointmentResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('appointment::appointment.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('appointment/appointment/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('appointment/appointment/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the appointment. * * @param Model $appointment * * @return Response */ public function destroy(AppointmentResourceRequest $request, Appointment $model) { try { $request = $request->all(); $model = AppointmentAction::run('destroy', $model, $request); $data = new AppointmentResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('appointment::appointment.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('appointment/appointment/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('appointment/appointment/' . $model->getRouteKey())) ->redirect(); } } }