I have a method called parser, in short its 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 this is a method that may be present in many controllers, where should I put this code?
- In what part of the Laravel framework should I allocate the file that will have this code?
- Any example or practical demonstration?