1 | initial version |
To bring in multiple rows from an excel sheet in Laravel, you can follow these steps:
composer require maatwebsite/excel
Create a new controller to handle the import process.
In the controller, add the following code to import the Excel file and retrieve the data from the first sheet:
use Maatwebsite\Excel\Facades\Excel;
public function import()
{
$data = Excel::toArray(new YourImport(), request()->file('file'));
// Do something with the data
}
Note: Replace YourImport
with the name of the class that extends the FromArray
or FromCollection
interface in Laravel Excel.
<form method="POST" enctype="multipart/form-data" action="{{ route('import') }}">
@csrf
<input type="file" name="file">
<button type="submit">Import</button>
</form>
import
method in the controller:Route::post('import', 'YourController@import')->name('import');