I'm using laravel 5.5 with MySQL database.
Here is my current code:
private function setValidationRule(Request $request,$actionCode) {
$rules = [];
$rules['odaydate'] = 'required|unique:empofday|date_format:"d-m-Y"';
return $rules;
}
public function postCreate(Request $request) {
//Previous code...
$validator = \Validator::make($request->all(),
$this->setValidationRule($request,$actionCode),
$this->setCustomValidationRuleMsg($request,$actionCode)
);
$validator->setAttributeNames($this->setValidationAttributeNames());
if ($validator->fails()) {
$view = $viewPri->withErrors($validator)->withInput();
} else {
$view = $viewSec;
}
return $view;
}
The posting data from client is DD-MM-YYYY = '15-10-2018'.
Then i want to validate the date uniqueness with the rule :$rules['odaydate'] = 'required|unique:empofday|date_format:"d-m-Y"';
Yes the validation is true (success) but the laravel generated sql was wrong to get the uniqueness :select count(*) as aggregate from empofday where odaydate = '15-10-2018'
so the resulting sql would be 0 instead of 1.
But if i try manual sql with the following code :select count(*) as aggregate from empofday where odaydate = '2018-10-01'
resulting value 1.
So, my question is how to set date format for laravel validating uniqueness on database to use d-m-Y format instead of Y-m-d?
Thanks for the help.