public function run() { \App\Models\Duo\Capability::create(['name' => 'push']); \App\Models\Duo\Capability::create(['name' => 'phone']); \App\Models\Duo\Capability::create(['name' => 'sms']); \App\Models\Duo\Capability::create(['name' => 'mobile_otp']); }
/** * @param User $duoUser * @param $user */ private function extractUserPhoneData(User $duoUser, $user) { \Log::debug('Processing User Phones', [$user['phones']]); //Create array to hold list of users phones $userPhoneList = []; foreach ($user['phones'] as $phone) { //Get an existing Duo Phone or create a new one $localPhone = Phone::firstOrCreate(['phone_id' => $phone['phone_id']]); //Populate Duo Phone fields $localPhone->name = $phone['name']; $localPhone->number = $phone['number']; $localPhone->extension = $phone['extension']; $localPhone->type = $phone['type']; $localPhone->platform = $phone['platform']; $localPhone->postdelay = $phone['postdelay']; $localPhone->predelay = $phone['predelay']; $localPhone->sms_passcodes_sent = $phone['sms_passcodes_sent']; $localPhone->actived = $phone['activated']; //Save the Duo Phone $localPhone->save(); //Push the Duo Phone ID onto the array $userPhoneList[] = $localPhone->id; //Create an array to hold the phones capabilities $phoneCapabilityList = []; //Loop through the phones assigned capabilities foreach ($phone['capabilities'] as $capability) { $cap = Capability::where('name', $capability)->first(); //Populate the array of capabilities $phoneCapabilityList[] = $cap->id; } //Sync the phones capabilities $localPhone->duoCapabilities()->sync($phoneCapabilityList); unset($phoneCapabilityList); } //Sync the Users Duo Phones $duoUser->duoPhones()->sync($userPhoneList); \Log::debug('Finished Processing User Phones'); }