/**
  * Deletes the specified service.
  *
  * @param int|string $id
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id)
 {
     $service = $this->service->findOrFail($id);
     if ($service->delete()) {
         flash()->success('Success!', 'Successfully deleted service.');
         return redirect()->route('services.index');
     }
     flash()->error('Error!', 'There was an issue deleting this service. Please try again.');
     return redirect()->route('services.show', [$id]);
 }
 public function getTimes($businessId, $serviceId, $date)
 {
     logger()->info(__METHOD__);
     logger()->info("businessId:{$businessId} serviceId:{$serviceId} date:{$date}");
     $business = Business::findOrFail($businessId);
     $service = Service::findOrFail($serviceId);
     $vacancies = $business->vacancies()->forDate(Carbon::parse($date))->get();
     $times = $this->splitTimes($vacancies, $service);
     return response()->json(['business' => $businessId, 'service' => ['id' => $service->id, 'duration' => $service->duration], 'date' => $date, 'times' => $times], 200);
 }
 public function confirmServiceOrder($serviceId)
 {
     try {
         $service = Service::findOrFail($serviceId);
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     return view('orders.confirmServiceOrder', ['service' => $service, 'firm' => Auth::user()->firm, 'p' => 'purchases']);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     try {
         $service = Service::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     $id = $request->route('services');
     $validationRules = ['short_name' => 'required|alpha_spaces_numbers_etc|max:255|unique:services,short_name,' . $id, 'unit' => 'required|alpha_spaces_numbers_etc|max:50', 'period' => 'required|alpha_spaces_numbers_etc|max:100', 'documents' => 'required|alpha_spaces_numbers_etc', 'price' => 'required|numeric'];
     $v = Validator::make($request->all(), $validationRules);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     }
     $service->short_name = $request->short_name;
     $service->full_name = $request->full_name;
     $service->unit = $request->unit;
     $service->period = $request->period;
     $service->documents = $request->documents;
     $service->price = $request->price;
     $service->need_station = $request->need_station ? 1 : 0;
     $service->save();
     return redirect('services')->with('alert-success', 'Услуга обновлена');
 }