0

i have some problem that Laravel WithHeadingRow does not working.

for example, i have this kind of excel file.

productId productName
2132 example_name

but i can't load rowheader using WithHeadingRow.

code:

class RandomRotationProductImport implements ToModel, WithHeadingRow
{
    public function model(array $row): ?RandomRotationProduct
    {
        return new RandomRotationProduct([
            'product_id' => $row['product_id'],
            'product_name' => $row['product_name']
        ]);
    }

    public function headingRow(): int
    {
        return 0;
    }
}

but this cause the error: "message": "Undefined index: product_id"

is there anything to solve this problem?

1 Answer 1

0
  • i think name must be the same as in file . so it should be
  • $row['productId']
  • $row['productName']
Sign up to request clarification or add additional context in comments.

1 Comment

I think that is not the answer. if you see this documentation: docs.laravel-excel.com/3.1/imports/heading-row.html, it's formatting automatically. and i also tried your solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.