Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nova data import to JSON database fields from CSV / XLS file #34

Open
LaravelLover069 opened this issue Apr 3, 2022 · 0 comments
Open

Comments

@LaravelLover069
Copy link

Sharing a solution here for all those who attempt to use this package to import CSV or XLS(X) data into a JSON database field:

Use Case:
Import cell values (e.g. address details) from CSV or XLS files into destination JSON columns.

Bildschirmfoto vom 2022-04-03 03-38-42

Solution:
Wrap the array mapping between the database JSON child node and the CSV / XLS column within the following function:

response()->json([ Add array here ])->getData()

Place address code example:

public function model(array $row)
    {
        return new Client([
            'name' => $row['client'],
            'location' => response()->json([
                'address' => $row['address'],
                'street'=> $row['street'],
                'house_no'=> $row['house_no'],
                'postcode'=> $row['postcode'],
                'city'=> $row['city'],
                'county'=> $row['county'],
                'country'=> $row['country']
            ])->getData(),
        ]);

@anaseqal
Would be great to have this somewhere in the readme / documentation as this might be useful for others too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant