$users * @property Collection $realUsers * * @method HasMany teamInvitations() * @method static OrganizationFactory factory() */ class Organization extends JetstreamTeam { use HasFactory; use HasUuids; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'name' => 'string', 'personal_team' => 'boolean', 'currency' => 'string', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'personal_team', ]; /** * The event map for the model. * * @var array */ protected $dispatchesEvents = [ 'created' => TeamCreated::class, 'updated' => TeamUpdated::class, 'deleted' => TeamDeleted::class, ]; /** * The model's default values for attributes. * * @var array */ protected $attributes = [ 'currency' => 'EUR', ]; /** * Get all the non-placeholder users of the organization including its owner. * * @return Collection */ public function allRealUsers(): Collection { return $this->realUsers->merge([$this->owner]); } public function hasRealUserWithEmail(string $email): bool { return $this->allRealUsers()->contains(function (User $user) use ($email): bool { return $user->email === $email; }); } /** * Get all the users that belong to the team. * * @return BelongsToMany */ public function users(): BelongsToMany { return $this->belongsToMany(Jetstream::userModel(), Jetstream::membershipModel()) ->withPivot([ 'id', 'role', 'billable_rate', ]) ->withTimestamps() ->as('membership'); } /** * @return BelongsToMany */ public function realUsers(): BelongsToMany { return $this->users() ->where('is_placeholder', false); } }