DEV Community

austin-nieves
austin-nieves

Posted on

Trying to input values in mysql with validation

I'm trying to input values in mysql that validates and use filter_var but it doesnt work and now error shows. this is my Controller

public function appointmentStore(Request $request) {

    $request->validate([
            'appointmentDate' => 'required',
            'appointmentTime' => 'required',
            'services' => 'required',  
            'Others' => 'nullable',
            'appointmentDescription' => 'required',
         ],
        [
            'appointmentDate.required' => 'Appointment Date is required',
            'appointmentTime.required' => 'Appointment Time is required',
            'services.required' => 'services is required',
            'Others.required' => 'Other is required ',
            'appointmentDescription.required' => 'appointmentDescription is required',
        ]);
            $appointment = new appointment();

            $appointment->appointmentDate = filter_var($request->appointmentDate, FILTER_SANITIZE_STRING);
            $appointment->appointmentTime = filter_var($request->appointmentTime, FILTER_SANITIZE_STRING);
            $appointment->Others = filter_var($request->Others, FILTER_SANITIZE_STRING);
            $appointment->appointmentDescription = filter_var($request->appointmentDescription, FILTER_SANITIZE_STRING);
            $appointment->services = filter_var($request->services, FILTER_SANITIZE_STRING);
            $appointment->save();

            return redirect()->route('setAppointment.show')->with('success', 'Appointment Saved'); 
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)