I have a .csv
where I need to import your data into the database. To do the import I'm using a Laravel library.
What's in here: link
In the code I'm doing 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 do the test and it's returning like this:
{"100005anel_o": "100006; O" RING} {"100005anel_o": "100024; O" {"100005anel_o": "100024; VITON RING \ n100494; GAXETA"} {"100005anel_o": "100506; SEALER"} {"100005anel_o": "100540; {"100005anel_o": "100552; SCRAPER"} {"100005anel_o": "100552; SCRAPER"} {"100005anel_o": "100598; SEALER"} {"100005anel_o": "100653; SEALER"}
Being that it is like this:
Itriedchangingtheparametersintheconfigurationfile,butitdidnotworkeither.
'csv'=>array(/*|--------------------------------------------------------------------------|Delimiter|--------------------------------------------------------------------------||ThedefaultdelimiterwhichwillbeusedtoreadoutaCSVfile|*/'delimiter'=>',',/*|--------------------------------------------------------------------------|Enclosure|--------------------------------------------------------------------------*/'enclosure'=>'"',
/*
|--------------------------------------------------------------------------
| Line endings
|--------------------------------------------------------------------------
*/
'line_ending' => "\r\n"
),
Actually the documentation explains almost nothing. Very scarce information.
1 - How do I get the values of rows and columns?