lundi 19 septembre 2016

Format date in validation message with Laravel 5

In my database i have date field in format Y-m-d H:i:s. What I want is, that this date is always bigger then this moment, when adding new item in database. I check this with laravel's validator:

Validator::make->($request->all(), [ 'date'=>'date|after:'.date(Y-m-d H:i:s) ]);

The problem is, that my page is in different languages, and each language has different date formats. Sometimes I want default format, sometimes i want d.m.Y H:i:s, and so on.. I made translations for different languages in resources/lang directory. For validation, I translated existing validation.php file, but the problem is, I don't know how to format date, if that is even possible with this approach. For now, my date is always in default format, the one I compare my input with. My validation.php file looks like this:

<?php

return [
   'after' => 'The :attribute must be a date after :date.'
];

My question now is, how to format :date attribute. Any help would be appreciated.

I tried already:

'after' => 'The :attribute must be date after'.date(format, strtotime(':date'))

But it doesn't do anything.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire