How to Load data from excel file then submit it in Laravel?

  ajax, jquery, laravel, php

I want my user to upload a product with an excel file to a fixed category. For this, I have to insert some input field values with the excel file’s value. My upload form HTML is :

<form action="">
    <input type="file" name="excel">
    <button id="">Load Excel File</button>
</form>
<form action="{{ route('product.store') }}" method="POST" enctype="multipart/form-data">
    @csrf
    <input type="hidden" value="25">
    <label for="">Price</label>
    <input type="text" placeholder="Product Price">
    <table>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Phone</th>
            <th>Action</th>
        </tr>
        @foreach()
        <tr>
            <td>{{ Name }}</td>
            <td>{{ Email }}</td>
            <td>{{ Phone }}</td>
            <td>
                <a href="">Remove</a>
            </td>
        </tr>
        @endforeach
    </table>
    <button type="submit">Submit</button>
</form>

Here the category_id will be the same for every product. Then the unit price will be given by the user.
Then select the excel file. Then click on the Load excel file button. It will read the data from an excel file and show it in the table. At the same time, it will match the table header and excel file header column. Here will show only the match header data. Then user can check the data. If wants user can remove data. Then submit button will insert a row for each table column into the database in the matched database column.

My question is:
How can I read an excel file and show the data on the table and remove data from the table? Is it possible with AJAX or something else?

Source: Laravel

Leave a Reply