Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Imports;
- use App\Patient;
- use App\User;
- use Illuminate\Support\Str;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Concerns\WithHeadingRow;
- class UserImport implements ToModel, WithHeadingRow
- {
- /**
- * @param array $row
- *
- * @return \Illuminate\Database\Eloquent\Model|null
- */
- public function model(array $row)
- {
- $user = User::create([
- 'name' => $row['name'],
- 'username' => $row['username'],
- 'email' => $row['email'],
- 'NIK' => $row['nik'],
- 'level' => $row['level'],
- 'department' => $row['department'],
- 'password' => bcrypt('omni123'),
- 'role' => $row['role'],
- 'health_care_id' => $row['unit']
- ]);
- if ($row['role'] == 'administrator') {
- $user->assignRole('administrator');
- } elseif ($row['role'] == 'user_mcu') {
- $user->assignRole('user_mcu');
- } elseif ($row['role'] == 'pasien') {
- $user->assignRole('pasien');
- } elseif($row['role'] == 'employee'){
- $user->assignRole('employee');
- }
- }
- public function headingRow(): int
- {
- return 1;
- }
- /**
- * Transform a date value into a Carbon object.
- *
- * @return \Carbon\Carbon|null
- */
- public function transformDate($value, $format = 'Y-m-d')
- {
- try {
- return \Carbon\Carbon::instance(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($value));
- } catch (\ErrorException $e) {
- return \Carbon\Carbon::createFromFormat($format, $value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement