/** * Display a listing of the resource. * * @return \Illuminate\View\View */ public function index() { if (\Auth::user() && \Auth::user()->profile->city_id != null) { $services = Services::where('time', '>=', new \DateTime('today'))->where('city_id', '=', \Auth::user()->profile->city_id)->get(); return view('services.index', compact('services')); } else { $services = Services::where('time', '>=', new \DateTime('today'))->get(); return view('services.index', compact('services')); } }
/** * This function takes care of the submit on Edit services Page * * @param POST data * * @return same page if validation fails, else services page with success message */ public function EditServicesSubmit() { //get form inputs $input = Request::all(); //if delete button is clicked if (isset($_POST['delserv'])) { $delsName = $input['delsname']; Services::where('Service', $delsName)->delete(); return redirect('dashboard/services')->with('message', 'Record Deleted Successfully'); } else { $iServiceName = $input['Service']; //create validation input array $rules = array('Service' => 'regex:/(^[A-Za-z ]+$)+/', 'Description' => 'regex:/[A-Za-z0-9 _.,!"]+$]*/'); //use laravel validation class $validation = Validator::make($input, $rules); //redirect if validation fails if ($validation->fails()) { return redirect('dashboard/services/edit?Service=' . $iServiceName)->withErrors($validation)->withInput(); } //get post data to variables $iServiceName = $input['Service']; $iDescription = $input['Description']; try { //insert the data to services table Services::where('Service', $iServiceName)->update(['Description' => $iDescription]); return redirect('dashboard/services')->with('message', 'Record Updated Successfully'); } catch (\Illuminate\Database\QueryException $e2) { return redirect('dashboard/services')->with('message', 'Record Update Failed'); } } }