%PDF- %PDF-
Direktori : /usr/local/apache/htdocs/app/Imports/ |
Current File : //usr/local/apache/htdocs/app/Imports/ClientsImport.php |
<?php namespace App\Imports; use App\Models\User; use Illuminate\Support\Facades\Hash; use Maatwebsite\Excel\Concerns\ToModel; use \PhpOffice\PhpSpreadsheet\Shared\Date; class ClientsImport implements ToModel { protected $index = 0; /** * @param array $row * * @return \Illuminate\Database\Eloquent\Model|null */ public function model(array $row) { $this->index = $this->index + 1; if( $this->index == 1 ) return null; if( empty($row[2]) ) return null; $client = new User; $data = [ 'phone' => $row[5] ?: rand(), 'name' => $row[2], 'email' => $row[6] ?: rand() . '@email.com', 'password' => Hash::make('123') ]; $client->fill($data); if( $client->save() ) { $client->assignRole('client'); $client->saveMeta([ 'nbdossier'=> $row[0], 'date_j' => @Date::excelToDateTimeObject( $row[1] )->format('Y-m-d'), 'manager' => $row[3], 'adress' => $row[4], 'ville' => '', 'website' => $row[7], 'agrement_number' => $row[8], 'rc' => $row[9], 'ice' => $row[10], 'remarques' => $row[12] ]); } return null; } }