Hello I'm trying to upload csv file and in instant next step move that data to database, but it's causing file not found exception. Please guide me where I'm wrong. Here is my existing code:
public function upload(Request $request) {
$path = $request->file('file')->storeAs('csv', 'sample.csv');
Storage::setVisibility($path, 'public');
Excel::filter('chunk')->load(storage_path($path))->chunk(250, function($results) {
foreach ($results as $row) {
User::create([
'username' => $row->username,
'contact' => $row->contact
]);
}
});
}
I found my mistake my self, storage_path actually give the directory path of "storage" folder, but when we save them using Storage, it will stores at "storage/app" folder so we just need to add "app/" before $path, and it should be
storage_path("app/" . $path)
That's works for me.