I am trying to read an excel file in laravel using Maatwebsite
But I don’t want to store it in the database.
public function store(Request $request)
{
$rules = array(
'file' => 'required',
);
$request->validate($rules);
try {
Excel::import($request->file('file'), function ($reader) {
foreach ($reader->toArray() as $key => $value) {
echo $key;
}
});
} catch (Exception $e) {
}
}
The echo show empty. I did $request->get("file") and it displays my filename which shows that it is passing an excel file.
2
Answers
try to create a import class like this:
and then use it like this :
check this for more info :
https://docs.laravel-excel.com/3.1/imports/collection.html
first, create an import file using the command,
This will create a file in the App/Imports
Then in the controller function, for example
and in the import file, you will have the function like this
in the $row you will have all the data available.
you can also use the model method.
you can read in detail from here
there are a lot of options where you can read and apply.