src/Traits/UsesProfiles.php
public function assignProfiles($profiles) : void
    {
        $profiles = (array) $profiles;
        foreach ($profiles as $profile) {
            $electedProfile = Profile::where('code', $profile)->first();

            // Profile exists and not assigned to user?
            if (!is_null($electedProfile) && !$this->hasProfile($profile)) {
                // Assign both role and permissions defined for this user profile.
                // Into the Spatie Permissions.
                $this->assignRole(Role::find([$electedProfile->role_id])->first()->name);
                $this->givePermissionTo(Permission::find([$electedProfile->permission_id])->first()->name);

                // Assign user profile into the profiles table.
                $this->profiles()->save($electedProfile);
            }
        }
    }
public function assignProfiles($profiles) : void
    {
        $profiles = (array) $profiles;
        foreach ($profiles as $profile) {
            $electedProfile = Profile::where('code', $profile)->first();

            // Profile exists and not assigned to user?
            if (!is_null($electedProfile) && !$this->hasProfile($profile)) {
                // Assign both role and permissions defined for this user profile.
                // Into the Spatie Permissions.
                $this->assignRole(Role::find([$electedProfile->role_id])->first()->name);
                $this->givePermissionTo(Permission::find([$electedProfile->permission_id])->first()->name);

                // Assign user profile into the profiles table.
                $this->profiles()->save($electedProfile);
            }
        }
    }
public function assignProfiles ( $ profiles ) : void { $ profiles = ( array ) $ profiles ; foreach ( $ profiles as $ profile ) { $ electedProfile = Profile :: where ( 'code' , $ profile ) -> first ( ) ; // Profile exists and not assigned to user? if ( ! is_null ( $ electedProfile ) && ! $ this -> hasProfile ( $ profile ) ) { // Assign both role and permissions defined for this user profile. // Into the Spatie Permissions. $ this -> assignRole ( Role :: find ( [ $ electedProfile -> role_id ] ) -> first ( ) -> name ) ; $ this -> givePermissionTo ( Permission :: find ( [ $ electedProfile -> permission_id ] ) -> first ( ) -> name ) ; // Assign user profile into the profiles table. $ this -> profiles ( ) -> save ( $ electedProfile ) ; } } }
Assigns profiles to the current model.

@param string|array $profiles The profile name(s) from the profiles table.

@return void
Assigns profiles to the current model .