Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 validation: date_format:Y.m.d not working

I try to validate a POST request.

The format is: d.m.Y (12.1.2017) My rule is required|date_format:d.m.Y for this field.

I get this error message:

InvalidArgumentException in Carbon.php line 425:
Unexpected data found.
Unexpected data found.
Data missing

If I change the . to - or even / it is working -> POST data changed before to match the rule.

I need the German format for this.

edit: My validation rules:

public function rules()
{
    return  [
        'title' => 'required|max:255',
        'expiration_date' => 'required|date_format:d.m.Y',
        //'description' => 'required',
        'provision_agent' => 'required|integer|between:0,100',
        'discount_consumer' => 'required|integer|between:0,100',
        'quota' => 'required|integer',
    ];
}
like image 672
mht Avatar asked Jan 12 '17 17:01

mht


1 Answers

Wrap your Format should work i just tried with 5.2 it's working fine.

public function rules()
{
    return  [
        'title' => 'required|max:255',
        'expiration_date' => 'required|date_format:"d.m.Y"',
        //'description' => 'required',
        'provision_agent' => 'required|integer|between:0,100',
        'discount_consumer' => 'required|integer|between:0,100',
        'quota' => 'required|integer',
    ];
}

But the error what you added in question InvalidArgumentException in Carbon.php line 425: it seems something else my guess you are using expiration_date some where in controller or model like this with Carbon

 echo Carbon::createFromFormat('Y-m-d', '12.1.2017');

You should try something like this

echo Carbon::parse('12.1.2017')->format('Y-m-d')
like image 109
vijaykumar Avatar answered Nov 10 '22 17:11

vijaykumar