1

I have a very weird problem. When I'm submitting the form, it throws an error with server-side validation.

BadMethodCallException

Method [validationRequired] does not exist.

My controller:

    public function store(Request $request)
{
    $rules = array(
        'DateDebut' => 'required',
        'TimeDebut' => 'required',
    );

    $messages = [
        'DateDebut.required'=>'La date de début de réunion est obligatoire.',
        'TimeDebut.required'=>'L\'heure de début de réunion est obligatoire.'
    ];
    $validator = Validator::make($request->all(),$rules,$messages);
    
    if ($validator->fails()) {
        return redirect()->route('demandes.create')
            ->withErrors($validator->errors()->messages());
    } else {
        return view('demandes.index');
    }
}

The controller fails on the methode $validator->fails()

7
  • Try to look into the value of $validator with this dd($validator), you can also check the values you pass to the validator this way to see if you notice anything off. Last thing to check is if you have the correct Validator in your code Commented Jan 13, 2020 at 10:59
  • can you give web.php Commented Jan 13, 2020 at 11:01
  • dd($validator') return a Validator object with all my data and all the rules . For the class Validator it call the interface of laravel framework with use Validator on the top of the controller. @ArijitJana what did you expect when you said "web.php" ? Commented Jan 13, 2020 at 13:02
  • I mean to say your web.php file in your routes folder @Damien Madaule Commented Jan 13, 2020 at 13:03
  • I can't publish all the web.php file but for this controller a use this part of the file : Route::resource('demandes', 'RequestController'); Commented Jan 13, 2020 at 13:14

1 Answer 1

0

Try changing this line

return redirect()->route('demandes.create')
            ->withErrors($validator->errors()->messages());

To this

return redirect()->route('demandes.create')
                ->withErrors($validator->errors()->toArray());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.