ExcelController.php 1.35 KB
Newer Older
Jenny Oktavia Doloksaribu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
<?php

namespace App\Http\Controllers;



use App\Http\Request;
use App\Http\Controllers\Controller;
use App\pembayaran;

use Illuminate\Support\Facades\Input;
use DB;
use Excel;

class ExcelController extends Controller
{
    
//IMPORT


      public function getImportPembayaran(){
        return view('excel.importPembayaran');
    }



//EXPORT



    public function getExportPembayaran(){
        $pembayaran=Pembayaran::all();
        Excel::create('Export Data Pembayaran', function($excel) use($pembayaran){
            $excel->sheet('Sheet 1', function($sheet) use($pembayaran){
                $sheet->fromArray($pembayaran);
            });
        })->export('xlsx');
    }




    //POST IMPORT


    public function postImportPembayaran(){

        Excel::load(Input::file('pembayaran'),function($reader){
            $reader->each(function($sheet){
                Pembayaran::firstOrCreate($sheet->toArray());
            });
        });

        
        $pembayarans = DB::table('tbl_transaksi')->paginate(10);
        return view('pembayaran.index',['pembayarans' => $pembayarans]);
    }



    //DELETE



     public function deleteAllPembayaran(){
        DB::table('tbl_transaksi')->delete();
        $pembayarans = DB::table('tbl_transaksi')->paginate(10);
        
        return view('pembayaran.index',['pembayarans' => $pembayarans]);
    }

    
}