From 1e21107e66c480dcb4dde60e76dcc5627f7dc9fa Mon Sep 17 00:00:00 2001 From: Louis Jeckel Date: Tue, 9 Feb 2021 14:28:48 +0100 Subject: [PATCH] UserImport --- app/Imports/UsersImport.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Imports/UsersImport.php b/app/Imports/UsersImport.php index 2bbdda4..a01fdf4 100644 --- a/app/Imports/UsersImport.php +++ b/app/Imports/UsersImport.php @@ -45,15 +45,18 @@ class UsersImport implements ToModel, WithValidation, WithHeadingRow ]); } - preg_match_all('/[0-9,+]+/', $row['phone'], $digits); - $phone = implode('', $digits[0]); + + $phone = null; + if(preg_match_all('/[0-9,+]+/', $row['phone'] ?? "", $digits)){ + $phone = implode('', $digits[0]); + } return new User([ 'first_name' => trim(Str::title($row['first_name'])), 'last_name' => trim(Str::title($row['last_name'])), 'email' => trim(Str::lower($row['email'])), - 'position' => Str::title($row['position']), - 'organization_id' => $org ? $org->id : null, + 'position' => Str::title($row['position'] ?? ''), + 'organization_id' => optional($org)->id, 'address_line_1' => $row['address_line_1'], 'postal_code' => $row['postal_code'], 'city' => $row['city'], -- 2.39.5