Search code examples
javascriptangularjslaravel-5restangular

How to get download file from Laravel 5.1 with AngularJS and ui-router


I have this code in laravel for export excel:

public function export_excel(Request $request){      
    $user = user::all();
    Excel::create('user', function($excel) use($user) {
        $excel->sheet('Sheet 1', function($sheet) use($user) {
            $sheet->fromArray($user);
        });
    })->download('xls');
}

and my route is:

Route::get('user/export/excel','UserController@export_excel');

and my html is:

<a><i class="fa fa-file-excel-o"></i> Export to Excel</a>

I want to send request from REST API with Restangular and after that get download file.


Solution

  • I solved problem with this:

    this.downloadExcel = function(){
            Restangular.one('user/export/excel').withHttpConfig({responseType: 'blob'}).get().then(function(response) {
                 var url = (window.URL || window.webkitURL).createObjectURL(response);
                 window.open(url,"_self");
            })
        }