• Write following in cmd
composer require Maatwebsite/excel
• after install /run upper composer........Maalwebsite/excel successfully check in composer.json that
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "5.2.*",
"Maatwebsite/excel": "^2.1"
},
• config/app.php/ in provides
Maatwebsite\Excel\ExcelServiceProvider::class,
• config/app.php/ in alias
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
• php artisan vendor:publish
• php artisan make:controller ExcelController
• open excel then create first_name,last_name,sex,email,phone then store datas and save as .csv
• in controlller for import
use App\Customer;
use Input;
use DB;
use Excel;
class ExcelController extends Controller
{
//
public function getImport()
{
return view('excel.importCustomer');
}
public function postImport()
{
Excel::load(Input::file('customer'),function($reader){
$reader->each(function($sheet){
Customer::firstOrCreate($sheet->toArray());
});
});
}
}
• in routes for import
Route::get('/getImport','ExcelController@getImport');
Route::post('/postImport','ExcelController@postImport');
• In controller for export
public function getExport()
{
$export=Customer::all();
Excel::create('Export Data',function($excel) use ($export){
$excel->sheet('Sheet 1',function($sheet) use ($export){
$sheet->fromArray($export);
});
})->export('xlsx');
}