vendredi 30 novembre 2018

how to import excel file in mysql using laravel 5.7 with vue JS

i was creating vue file for inpute Excel or csv file laravel 5.7 i was using Maatwebsite/Laravel-Excel dont know how to route there things it if my first time to make app like laravel with vue JS Don't know what to doo there is Vue file

    <template>
    <div class="container">
        <div class="row mt-5">
          <div class="col-md-12">
            <div class="card">
              <div class="card-header">
                <h3 class="card-title">Students</h3>

                <div class="card-tools">
                    <button class="btn btn-success" data-toggle="modal" data-target="#exampleModal">Add New <i class="fas fa-user-plus"></i></button>
                    <button class="btn btn-primary" data-toggle="modal" data-target="#importModel">Import <i class="fas fa-file-excel"></i></button>
                    <button class="btn btn-warning" data-toggle="modal" data-target="#export">Export <i class="fas fa-file-excel"></i></button>

                </div>
              </div>

            </div>
            <!-- /.card -->
          </div>
        </div><!-- /.row -->
        <!-- Modal -->
        <div class="modal fade" id="importModel" tabindex="-1" role="dialog" aria-labelledby="importModelLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="importModelLabel">Import Excel</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form method="POST"   enctype="multipart/form-data">
                <div class="modal-body">
                        <div class="form-group">
                            <label>Import</label>
                            <input type="file" name="excel_file"
                                class="form-control" :class="{ 'is-invalid': form.errors.has('excel_file') }">
                        </div>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save Student</button>
                </div>
                </form>
            </div>
        </div>
        </div>

        <!--Exit Modal-->
    </div>
</template>

<script>
    export default {
        data(){
            return{
                form: new Form({
                    first_name:'',
                    last_name:'',
                    email:'',
                    password:'',
                    designation:''
                })
            }
        },
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

set a post route to import data in web.php file that will route the things as pr laravelExcel

Route::post('importExcel', 'API/StudentMasterController@import');

in a controller file

public function import()
{
    Excel::import(new StudentImport, request()->file('excel_file'));
      //return redirect('/')->with('success', 'All good!');
}

and in a APP/import/studentmaster.php file

public function model(array $row)
{
    return new Student_master([
        'EnrollmentNo'     => $row[22],
    ]);
}



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KKi2n5
via IFTTT

Aucun commentaire:

Enregistrer un commentaire