Replies: 1 comment 4 replies
-
Try disabling transactions https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/config/excel.php#L278
Try diving into some documentation/tutorials https://www.w3schools.com/php/func_array_map.asp |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to import a CSV file and I need to change the extension field type from Integer to String.
What would be the best way to do that?
Here is an example of the CSV file that I'm importing:
import_data.txt
"first_name","last_name","email","extension"
"fake","user","[email protected]","123"
"fake","user","[email protected]","123"
"fake","user","[email protected]","123"
"fake","user","[email protected]","123"
"fake","user","[email protected]","123"
This is how my Controller looks like:
This is how my "ExtensionsImport.php" file looks like:
If I do it like this. I get this Laravel error:
QUESTION 1: I guess it's because I'm not using any DB. My data comes (GET) as goes (POST/PUT) by doing API calls.
Is my assumption correct? If I don't use a DB, then I cannot use "Excel::import"?
my only options are to use "Excel::toArray" or "Excel::toCollection" ?
If I change the code and do it like this, then I do receive the data as an array but the extension field comes as Integer. I need it to be a String. I've tried using "array_map('str_getcsv', file($data));" or "foreach" with "(string) $data['extension']" but so far nothing seems to work. Some one suggested using "array_map()" but I don't know how to use it.
QUESTION 2: How can I change the extension field to be a string?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions