1. Go to this page and download the library: Download usmanhalalit/laracsv 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/ */
usmanhalalit / laracsv example snippets
$users = User::get(); // All users
$csvExporter = new \Laracsv\Export();
$csvExporter->build($users, ['email', 'name'])->download();
$csvExporter = new \Laracsv\Export();
$users = User::get();
// Register the hook before building
$csvExporter->beforeEach(function ($user) {
$user->created_at = date('f', strtotime($user->created_at));
});
$csvExporter->build($users, ['email', 'name' => 'Full Name', 'created_at' => 'Joined']);
// The notes field doesn't exist so values for this field will be blank by default
$csvExporter->beforeEach(function ($user) {
// Now notes field will have this value
$user->notes = 'Add your notes';
});
$csvExporter->build($users, ['email', 'notes']);