Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To bring in multiple rows from an excel sheet in Laravel, you can follow these steps:

  1. Install the Maatwebsite/Laravel-Excel package using composer.
composer require maatwebsite/excel
  1. Create a new controller to handle the import process.

  2. 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.

  1. In the view, add a file input to upload the Excel file:
<form method="POST" enctype="multipart/form-data" action="{{ route('import') }}">
    @csrf
    <input type="file" name="file">
    <button type="submit">Import</button>
</form>
  1. Finally, add a route to the import method in the controller:
Route::post('import', 'YourController@import')->name('import');