2
I have a method called parser, in short your code is:
public function parser($local) {
$file = storage_path($local);
$csv = Reader::createFromPath($file);
// remove cabeçalho (ignora a primeira linha
// $novo = $reader->setOffset(0)->fetchAll();
// retorna o cabeçalho
// $headers = $csv->fetchOne();
foreach ($csv as $row) {
$novo[] = ["nome" => $row[0], "idade" => $row[1], "outro" => $row[2]];
}
\DB::table('teste')->insert($novo);
}
The above method will be used in several different controllers, so my doubts are:
- Because it is a method that may be present in many controllers, where should I put this code?
- In which part of the structure of Laravel should I allocate the file that will have this code?
- Some example or practical demonstration?