-
-
Save cursosdesarrolloweb/b783594a9385753d6f165dce390cefe4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Imports; | |
use App\Models\User; | |
use Illuminate\Support\Str; | |
use Maatwebsite\Excel\Concerns\ToModel; | |
use Maatwebsite\Excel\Concerns\WithStartRow; | |
class UsersImport implements ToModel, WithStartRow | |
{ | |
/** | |
* EXCEL COLUMNS FORMAT | |
* NAME | EMAIL | |
* @param array $row | |
*/ | |
public function model(array $row) | |
{ | |
$password = Str::random(8); | |
$userExists = User::whereEmail($row[1])->first(); | |
if ( ! $userExists) { | |
$user = User::create( | |
[ | |
'name' => $row[0], | |
'email' => $row[1], | |
'password' => bcrypt($password), | |
] | |
); | |
return $user; | |
} | |
} | |
public function startRow(): int { | |
return 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment