33 lines
905 B
PHP
33 lines
905 B
PHP
<?php
|
|
|
|
namespace App\Imports;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use Maatwebsite\Excel\Concerns\WithValidation;
|
|
|
|
class UsersImport implements ToModel, WithHeadingRow, WithValidation
|
|
{
|
|
public function model(array $row)
|
|
{
|
|
return new User([
|
|
'first_name' => $row['first_name'],
|
|
'last_name' => $row['last_name'],
|
|
'email' => $row['email'],
|
|
'status' => $row['status'] ?? 'active',
|
|
'password' => Hash::make($row['password'] ?? 'password123'),
|
|
]);
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'first_name' => 'required|string|max:255',
|
|
'last_name' => 'required|string|max:255',
|
|
'email' => 'required|email|unique:users,email',
|
|
];
|
|
}
|
|
}
|