Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tambahin ini dibawah container-fluid
- <div class="col-sm-12 mb-3">
- <button type="button" class="btn-info" data-toggle="modal" data-target="#exampleModal">
- Export To Excel
- </button>
- </div>
- //tambahin pop up modal
- <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="exampleModalLabel">Export All Data Locations To Excel</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <div class="modal-body">
- <form action="{{route('locations.export')}}" method="POST" >
- {{csrf_field()}}
- <div class="form-group {{$errors->has('start_date') ? 'has-error' : ' '}}">
- <label for="start_date">Start Date :</label>
- <input name="start_date" type="date" class="form-control" id="start_date" aria-describedby="start_date">
- @if($errors -> has('start_date'))
- <span class="help-block">{{$errors->first('start_date')}}</span>
- @endif
- </div>
- <div class="form-group {{$errors->has('end_date') ? 'has-error' : ' '}}">
- <label for="end_date">End Date :</label>
- <input name="end_date" type="date" class="form-control" id="end_date" aria-describedby="end_date">
- @if($errors -> has('end_date'))
- <span class="help-block">{{$errors->first('end_date')}}</span>
- @endif
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
- <button type="submit" class="btn btn-primary">Download</button>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- //bikin file di folder App/Exports/LocationExportAll.php
- <?php
- namespace App\Exports;
- use App\Location;
- use Illuminate\Contracts\View\View;
- use Maatwebsite\Excel\Concerns\FromView;
- class LocationExport implements FromView
- {
- public function __construct(string $start, string $end){
- $this->start = $start;
- $this->end = $end;
- }
- public function view(): View
- {
- return view('locations.locationExport', [
- 'datas' => Location::where('tanggal','>=',$this->start)->where('tanggal','<=',$this->end)->get()
- ]);
- }
- }
- //bikin route
- Route::post('/export-excel', 'LocationController@cetak_excel')->name('locations.export');
- //bikin fuction di Locations Controller
- public function cetak_excel(Request $request){
- // dd('ok');
- // dd($request->start_date);
- $nama_file = 'laporan_LokasiKaryawan_'.date('Y-m-d_H-i-s').'.xlsx';
- return Excel::download(new LocationExport($request->start_date,$request->end_date), $nama_file);
- }
- // taro file view yg dikirim aji di whatsapp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement