I am implementing Laravel-Excel into my project and could not figure out the validation.
I try to upload the xlsx
file with one row of data in it but still, the import throws required
error.
Following is my EventResultImport
code
namespace App\Imports;
use App\Models\Data\EventResult;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithValidation;
use Maatwebsite\Excel\Imports\HeadingRowFormatter;
class EventResultImport implements ToModel, WithValidation, WithHeadingRow
{
use Importable;
public function model(array $row)
{
HeadingRowFormatter::default('none');
return new EventResult([
'event_id' => $row[0],
'event_name' => $row[1],
]);
}
public function rules(): array
{
return [
//'EventId' => 'required|numeric', Tried this
//'*.EventId' => 'required|numeric', Tried this
'0' => 'required|numeric'
];
}
}
I get error on second-row event if there is numeric data in column EventId
.
Thank you