40 lines
841 B
PHP
40 lines
841 B
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithStartRow;
|
|
|
|
class UserImport implements ToModel, WithStartRow
|
|
{
|
|
/**
|
|
* @param array $row
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Model|null
|
|
*/
|
|
public function model(array $row)
|
|
{
|
|
$name = $row[1];
|
|
$username = explode(' ', $name)[0];
|
|
$email = strtolower($username) . '@gmail.com';
|
|
$password = Hash::make('man3bwi');
|
|
$role = 'siswa';
|
|
|
|
return new User([
|
|
'name' => $name,
|
|
'username' => $username,
|
|
'email' => $email,
|
|
'password' => $password,
|
|
'role' => $role,
|
|
]);
|
|
}
|
|
|
|
public function startRow(): int
|
|
{
|
|
return 2;
|
|
}
|
|
|
|
}
|