PHP code example of bhagat / excel

1. Go to this page and download the library: Download bhagat/excel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bhagat / excel example snippets

 
web.php / Controller
use App\Exports\ExportUser;
Route::get('/excel', function(){
    return Excel::download(new ExportUser, 'users.xlsx');
});

App\Exports\ExportUser.php

    namespace App\Exports;
	use App\Models\User;
	use Bhagat\Excel\Concerns\FromCollection;

	class ExportUser implements FromCollection {
		public function collection()
		{
			return User::select('name','email')->get();
		}
	}