Closed nicolastorgato closed 4 years ago
Validation is executed before your. model function. I don't think you can use the date:
rule for it, because it's not an actual date yet. You most likely need to implement a custom rule that tries to convert the excel timestamp to a date and validate it like that.
I can't fix the problem by myself, but patience. Thanks anyway!
What I meant with custom rules: https://laravel.com/docs/7.x/validation#using-rule-objects
If you show me what you tried, I'll try to help.
@nicolastogato see if it help you.
What I did is applying the min/max rule like that:
public function rules() : array
{
$today = Date::timestampToExcel(today()->timestamp);
$deliveryDateConfirmedMax = Date::timestampToExcel($this->purchaseRequest->created_at->addWeekdays(5)->timestamp);
return [
'delivery_date_confirmed' => "nullable|required_unless:*.quantity_confirmed,,0|min:$today|max:$deliveryDateConfirmedMax"
];
}
Custom rules as @patrickbrouwers advise is better though.
Prerequisites
Versions
Description
I'm trying to import CSV/Excel files into a table. I successfully managed to load CSV files (doing the same exact thing as the Excel), but I have a problem with Excel files, in particular with the date validation. Basically the validation always tells me that the date is not a date (but it actually is), I tried with different formats but nothing changes.
This is my code: OrdinanzaImport.php (this is the model import)
controller.php
I also tried to use the following code that I found on the package issues but nothing:
This is the Excel file if you want to check: https://easyupload.io/sq2ift
How could this be fixed?
Thanks!