Reputation: 171
I am using Maatwebsite/Excel to import CSV files. My code looks like this tutorial: http://itsolutionstuff.com/post/laravel-5-import-export-to-excel-and-csv-using-maatwebsite-exampleexample.html I marged both functions and my script gets file and returns file/
But despite many attempts I can't skip uploading file. It means, that I have CSV file in special folder, and I would like to get this file to process data, without uploading. It will automatically get file (maybe file_get_contents ?), and pass it to Illuminate\Support\Facades\Input.
Upvotes: 0
Views: 2566
Reputation: 171
I found solution. We can skip if (Input::hasFile('import_file')) {
and $path
variable set to our CSV file path
Upvotes: 0
Reputation: 316
This is the perfect way to import your csv in laravel 5.*
public function importExcel() {
if (Input::hasFile('import_file')) {
$path = Input::file('import_file')->getRealPath();
$data = Excel::load($path, function($reader) {
})->get();
if (!empty($data) && $data->count()) {
$count = 0;
foreach ($data as $key => $d) {
$insert = array();
$insert['name'] = $value->name;
$this->user->create($insert);
}
}
}
}
Upvotes: 2
Reputation: 424
You can read your excel file using this code
// for sheet 1
$excelData = $excel->selectSheetsByIndex(0)->load($yourFilePath)->get();
print_r($excelData);
Upvotes: 0