import export data into excel 02.40 Catatan Mahasiswa No comments Aturannya : Saya Menggunakan : Php Versi (7.2.6) Laravel Versi (5.5) 1. Masukan kedalam composer.json=> "maatwebsite/excel": "~2.1.0" 2. Buka config/app.php 'providers' => [ .... 'Maatwebsite\Excel\ExcelServiceProvider', ], 'aliases' => [ .... 'Excel' => 'Maatwebsite\Excel\Facades\Excel', ], kemudian ketikan di terminal=> composer update 3. Buat Controller dengan file DataKaryawanController.php hasFile('sample_file')){ $path = $request->file('sample_file')->getRealPath(); $data = \Excel::load($path)->get(); if($data->count()){ foreach ($data as $key => $value) { $arr[] = ['title' => $value->title, 'body' => $value->body]; } if(!empty($arr)){ DB::table('products')->insert($arr); dd('Insert Recorded successfully.'); } } } dd('Request data does not have any files to import.'); } /** * Create a new controller instance. * * @return void */ public function exportFile($type){ $products = Product::get()->toArray(); return \Excel::create('hdtuto_demo', function($excel) use ($products) { $excel->sheet('sheet name', function($sheet) use ($products) { $sheet->fromArray($products); }); })->download($type); } } 4.Tambahkan pada routes=>web.php Route::get('export-file-karyawan/{type}', 'admin\DataKaryawanController@exportFile')->name('export.file_karyawan'); 5. Buat File didalam folder views simpan dengan perhitungangaji.blade.php @extends('layouts.admin') @section('content') Data Karyawan Home List Data Karyawan {!! Form::open(['method'=>'GET','url'=>'/searchdatakaryawan','role'=>'search']) !!} Search {!! Form::close() !!} Save File No. Nama NIP/NIDN Gaji Tunjangan Total Gaji @foreach($data_karyawan as $i=>$data_karyawans) {{$i+1}} {{ $data_karyawans->nama_lengkap }} {{ $data_karyawans->nip }} {{ $data_karyawans->gaji }} {{ $data_karyawans->gaji*0.01 }} {{ $data_karyawans->gaji*0.01 + $data_karyawans->gaji+400000 }} @endforeach @endsection Share This: Facebook Twitter Google+ Stumble Digg Kirimkan Ini lewat EmailBlogThis!Bagikan ke XBerbagi ke Facebook
0 komentar:
Posting Komentar