How to validate germany date format in Laravel?

Laravel

I have this german date: 18.11.2020 09:32 and I want to validate this datetime format via the Laravel validation class. I've tried a couple of approaches yet but it always validates the date wrong.

PHP Programming Software Question created: 2020-11-18 08:53 zulu

4

You could use the validation class of Laravel to validate a german date format in a nice way and easy way. Simply configure your validation rules based on the date_format validator on your controller action. In that way you controller could look like this: 

/**
 * Proceed edit
 *
 * @param Request $request
 */
public function add (Request $request)
{

    //validate
    $validate = Validator::make($request->all(), [
        'created_at' => 'required|date_format:d.m.Y H:i:s',
    ]);

    if (!$validate->fails()) {
        //validation successfull
    }
}

German date validation rule for laravel:

'date_format:d.m.Y H:i:s'
answered 2020-12-04 07:36 Zunami