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');
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-04-15 11:00:00 +0000
Seen: 9 times
Last updated: Dec 01 '22
What is the process of creating a barplot that includes a threshold using matplotlib?
How can the theme settings be established in Vuetify3?
How can an undirected graph be created in Gephi?
The size of the plot returned by df.hist() is not the desired one.
Is there a way to streamline my imports in SvelteKit with Vite bundler, such as utilizing $lib/?
How can I get my existing bot to function with my slash command using Discord.Py?
What does it mean when tsm import encounters an 'Internal error processing applyMigrations' error?
Why does the import of a dependency fail in a Node.js script when running inside a Docker container?