public function attachRole($role) { if (is_object($role)) { $role = $role->getKey(); } if (is_array($role)) { $role = $role['id']; } $this->roles()->attach($role); }