roles icon indicating copy to clipboard operation
roles copied to clipboard

Duplicate roles being added with attachRoles

Open iredmedia opened this issue 5 years ago • 0 comments

	/**
	 * Attach role to a user.
	 *
	 * @param int|\HttpOz\Roles\Models\Role $role
	 *
	 * @return bool
	 */
	public function attachRole( $role ) {
		if ( ! collect( $this->getRoles() )->contains( $role ) ) {
			$this->clearCached();
			$this->roles()->attach( $role );
		}

		return true;
	}

Should prevent duplicate roles, however:

User::find(1)->getRoles()->contains(Role::find(1)) => true collect(User::find(1)->getRoles())->contains(Role::find(1)) => false

Seems that collect is breaking this.

iredmedia avatar May 01 '20 16:05 iredmedia