SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // tambahin ini dibawah container-fluid
  2. <div class="col-sm-12 mb-3">
  3.     <button type="button" class="btn-info"  data-toggle="modal" data-target="#exampleModal">
  4.        Export To Excel
  5.    </button>
  6. </div>
  7.  
  8. //tambahin pop up modal
  9.  
  10. <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  11.     <div class="modal-dialog" role="document">
  12.         <div class="modal-content">
  13.         <div class="modal-header">
  14.             <h5 class="modal-title" id="exampleModalLabel">Export All Data Locations To Excel</h5>
  15.             <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  16.               <span aria-hidden="true">&times;</span>
  17.             </button>
  18.         </div>
  19.         <div class="modal-body">
  20.           <form action="{{route('locations.export')}}" method="POST" >
  21.               {{csrf_field()}}
  22.               <div class="form-group {{$errors->has('start_date') ? 'has-error' : ' '}}">
  23.                   <label for="start_date">Start Date :</label>
  24.                   <input name="start_date" type="date" class="form-control" id="start_date" aria-describedby="start_date">
  25.                   @if($errors -> has('start_date'))
  26.                   <span class="help-block">{{$errors->first('start_date')}}</span>
  27.                   @endif
  28.               </div>
  29.               <div class="form-group {{$errors->has('end_date') ? 'has-error' : ' '}}">
  30.                 <label for="end_date">End Date :</label>
  31.                 <input name="end_date" type="date" class="form-control" id="end_date" aria-describedby="end_date">
  32.                 @if($errors -> has('end_date'))
  33.                 <span class="help-block">{{$errors->first('end_date')}}</span>
  34.                 @endif  
  35.               </div>
  36.              
  37.               <div class="modal-footer">
  38.                   <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  39.                   <button type="submit" class="btn btn-primary">Download</button>
  40.               </div>
  41.           </form>
  42.         </div>
  43.         </div>
  44.     </div>
  45.   </div>
  46.  
  47. //bikin file di folder App/Exports/LocationExportAll.php
  48.  
  49. <?php
  50.     namespace App\Exports;
  51.  
  52.     use App\Location;
  53.     use Illuminate\Contracts\View\View;
  54.     use Maatwebsite\Excel\Concerns\FromView;
  55.    
  56.  
  57.     class LocationExport implements FromView
  58.     {
  59.         public function __construct(string $start, string $end){
  60.             $this->start = $start;
  61.             $this->end = $end;
  62.         }
  63.  
  64.    
  65.  
  66.         public function view(): View
  67.         {
  68.            
  69.             return view('locations.locationExport', [
  70.                 'datas' => Location::where('tanggal','>=',$this->start)->where('tanggal','<=',$this->end)->get()
  71.             ]);
  72.         }
  73.     }
  74.            
  75. //bikin route
  76. Route::post('/export-excel', 'LocationController@cetak_excel')->name('locations.export');
  77.  
  78. //bikin fuction di Locations Controller
  79. public function cetak_excel(Request $request){
  80.         // dd('ok');
  81.         // dd($request->start_date);
  82.         $nama_file = 'laporan_LokasiKaryawan_'.date('Y-m-d_H-i-s').'.xlsx';
  83.         return Excel::download(new LocationExport($request->start_date,$request->end_date), $nama_file);
  84.     }
  85.  
  86. // taro file view yg dikirim aji di whatsapp
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top