2
I have a .csv
where I need to import your data into the database. I am using an Laravel library to import it.
What is this one: https://github.com/Maatwebsite/Laravel-Excel
In the code I’m doing like this:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Excel;
use Illuminate\Http\Request;
class ImporterController extends Controller {
# Página de Importação da Lista de Produtos para Base de Dados
public function getIndex(){
\Excel::load('public/upload/file.csv', function($reader) {
// Getting all results
$results = $reader->get();
// ->all() is a wrapper for ->get() and will work the same
$results = $reader->all();
foreach ($results as $key => $var) {
echo $var."<br>";
}
});
}
I’m using a small file .csv
to take the test and is returning like this:
{"100005anel_o":"100006;O RING"} {"100005anel_o":"100024;O RING"} {"100005anel_o":"100024;VITON RING n100494;GASKET"} {"100005anel_o":"100506;SEALER"} {"100005anel_o":"100540;SEALER"} {"100005anel_o":"100552;SCRAPER"} {"100005anel_o":"100552;SCRAPER"} {"100005anel_o":"100598;SEAL"} {"100005anel_o":"100653;SEAL"}
Being that he is:
I tried to change the parameters in the configuration file, but it didn’t work either.
'csv' => array(
/*
|--------------------------------------------------------------------------
| Delimiter
|--------------------------------------------------------------------------
|
| The default delimiter which will be used to read out a CSV file
|
*/
'delimiter' => ',',
/*
|--------------------------------------------------------------------------
| Enclosure
|--------------------------------------------------------------------------
*/
'enclosure' => '"',
/*
|--------------------------------------------------------------------------
| Line endings
|--------------------------------------------------------------------------
*/
'line_ending' => "\r\n"
),
In fact the documentation does not explain almost anything. Very little information.
1 - How to get the values of rows and columns ?