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;
$lazyCollection = SimpleCsv::import(storage_path('collection.csv'));
use BayAreaWebPro\SimpleCsv\SimpleCsv;
use App\SimpleCsv\MyCustomCast;
$lazyCollection = SimpleCsv::import(storage_path('collection.csv'), [
MyCustomCast::class
]);
use BayAreaWebPro\SimpleCsv\Casts\NumericValues;
use BayAreaWebPro\SimpleCsv\Casts\EmptyValuesToNull;
declare(strict_types=1);
namespace App\Csv\Casts;
use Carbon\Carbon;
use Illuminate\Config\Repository;
class ParseTimestamps
{
/**
* Inject services by adding a constructor.
*/
public function __construct(public Repository $config)
{
//
}
/**
* Invoked for each row.
*/
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;
}
}