/** * This function takes care of the submit on Add services Page * * @param POST data * * @return same page if validation fails, else services page with success message */ public function AddServicesSubmit() { //get form inputs $input = Request::all(); //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/add')->withErrors($validation)->withInput(); } //get post data to variables $iServiceName = $input['Service']; $iDescription = $input['Description']; $iSlug = str_replace(" ", "-", $iServiceName); $iSlug = strtolower($iSlug); try { //insert the data to services table Services::insert([['Service' => $iServiceName, 'ServiceSlug' => $iSlug, 'Description' => $iDescription]]); return redirect('dashboard/services')->with('message', 'Record Added Successfully'); } catch (\Illuminate\Database\QueryException $e2) { return redirect('dashboard/services')->with('message', 'Record Update Failed'); } }