PHP code example of bayareawebpro / laravel-simple-csv
1. Go to this page and download the library: Download bayareawebpro/laravel-simple-csv 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/ */
bayareawebpro / laravel-simple-csv example snippets
use BayAreaWebPro\SimpleCsv\SimpleCsv;
use BayAreaWebPro\SimpleCsv\Casts\EmptyValuesToNull;
use BayAreaWebPro\SimpleCsv\Casts\NumericValues;
$lazyCsvCollection = SimpleCsv::import(storage_path('collection.csv'), [
EmptyValuesToNull::class,
NumericValues::class,
]);
declare(strict_types=1);
namespace App\Csv\Casts;
use Carbon\Carbon;
class Timestamps
{
/** Invoked for each row in import collection. */
public function __invoke(array $item): array
{
foreach ($item as $key => $value){
if(in_array($key, ['created_at', 'updated_at'])){
$item[$key] = Carbon::parse($value);
}
}
return $item;
}
}