validation in importer
Why do i keep getting this error? "The name field is required."
ImportColumn::make('name')
->requiredMapping()
->rules(['required', 'string', 'max:255']),ImportColumn::make('name')
->requiredMapping()
->rules(['required', 'string', 'max:255']), public function resolveRecord(): ?Collection
{
try {
// Find or create collection based on ID
$collection = Collection::firstOrNew([
'id' => $this->data['id']
]);
// Set additional fields
$collection->name = $this->data['name'];
$collection->slug = $this->data['slug'] ?? null;
$collection->description = $this->data['description'] ?? null;
$collection->images = $this->data['images'] ?? ['/images/default_image.png'];
$collection->media_id = $this->data['media_id'] ?? null;
$collection->parent_id = $this->data['parent_id'] ?? null;
$collection->is_visible = $this->data['is_visible'] ?? true;
$collection->tags = $this->data['tags'] ?? null;
$collection->data = $this->data['data'] ?? null;
return $collection;
} catch (\Exception $e) {
Log::error('Collection import error', [
'data' => $this->data,
'error' => $e->getMessage()
]);
return null;
}
} public function resolveRecord(): ?Collection
{
try {
// Find or create collection based on ID
$collection = Collection::firstOrNew([
'id' => $this->data['id']
]);
// Set additional fields
$collection->name = $this->data['name'];
$collection->slug = $this->data['slug'] ?? null;
$collection->description = $this->data['description'] ?? null;
$collection->images = $this->data['images'] ?? ['/images/default_image.png'];
$collection->media_id = $this->data['media_id'] ?? null;
$collection->parent_id = $this->data['parent_id'] ?? null;
$collection->is_visible = $this->data['is_visible'] ?? true;
$collection->tags = $this->data['tags'] ?? null;
$collection->data = $this->data['data'] ?? null;
return $collection;
} catch (\Exception $e) {
Log::error('Collection import error', [
'data' => $this->data,
'error' => $e->getMessage()
]);
return null;
}
}