How to format date in Unique Rules
In my Laravel5.8 project I have this Unique Rules code:
'goal_type_id' => [
'required',
Rule::unique('appraisal_goals')->where(function ($query) {
return $query->where('appraisal_identity_id', $this->appraisal_identity_id)
->where('goal_type_id', $this->goal_type_id)
->where('start_date', $this->start_date);
})
],
How do I format my start_date in the code to:
'date',
'date_format:Y-m-d',
Thank you
@noblemfd
Have you thought this way to implement?
Carbon\Carbon::parse($this->start_date)->format('Y-m-d')
'goal_type_id' => [
'required',
Rule::unique('appraisal_goals')->where(function ($query) {
return $query->where('appraisal_identity_id', $this->appraisal_identity_id)
->where('goal_type_id', $this->goal_type_id)
->where('start_date', Carbon\Carbon::parse($this->start_date)->format('Y-m-d'));
})
],
Please or to participate in this conversation.