Laravel Validate and Remember Checkbox Input and Date
i have a form where the user can select multiple certificates they have but for each selected certificate they have to input the date it was received. trying to figure out:
make the date input for that checkbox required if the checkbox is checked
how to get and validate the specified date for that input like: date|before:today
remember old data in form for date input if validation fails
i'm using FormRequests to validate inputs.
the ???? means how to catch errors for the date input of that checkbox if any
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SaveMembershipRequest extends FormRequest {
public function authorize() {
return true;
}
public function rules() {
return [
'certificates.*' => [
// HOW TO FILL THIS PART
],
];
}
public function messages() {
return [
// WHAT GOES HERE
'certificates.*' => 'we do not know about this certificate',
'certificates.*.date_received' => 'we do not know about this certificate',
];
}
}
Then in the Form request, you can do something like this :
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class SaveMembershipRequest extends FormRequest {
public function authorize() {
return true;
}
public function rules() {
return [
'certificates' => "array|min:1", // Should contain atleast one certifcate.
'certificates.*.certificate' => "required",
'certificates.*.date_received' => "required|date|before:today",
];
}
public function messages() {
return [
// WHAT GOES HERE
'certificates.*' => 'we do not know about this certificate',
'certificates.*.date_received' => 'we do not know about this certificate',
];
}
}