PHP code example of philiprehberger / laravel-csv-import
1. Go to this page and download the library: Download philiprehberger/laravel-csv-import 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/ */
philiprehberger / laravel-csv-import example snippets
namespace App\Imports;
use App\Models\User;
use PhilipRehberger\CsvImport\Contracts\ImportHandler;
class UserImportHandler implements ImportHandler
{
public function rules(): array
{
return [
'first_name' => ['irst_name',
'Last Name' => 'last_name',
'Email' => 'email',
];
}
public function handle(array $row): void
{
User::create($row);
}
public function uniqueBy(): ?string
{
return 'email';
}
}