$users * @property Collection $realUsers * @property-read Collection $teamInvitations * @property Member $membership * @property NumberFormat $number_format * @property CurrencyFormat $currency_format * @property DateFormat $date_format * @property IntervalFormat $interval_format * @property TimeFormat $time_format * * @method HasMany teamInvitations() * @method static OrganizationFactory factory() */ class Organization extends JetstreamTeam implements AuditableContract { use CustomAuditable; /** @use HasFactory */ use HasFactory; use HasUuids; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'name' => 'string', 'personal_team' => 'boolean', 'currency' => 'string', 'employees_can_see_billable_rates' => 'boolean', 'number_format' => NumberFormat::class, 'currency_format' => CurrencyFormat::class, 'date_format' => DateFormat::class, 'interval_format' => IntervalFormat::class, 'time_format' => TimeFormat::class, ]; /** * 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 = [ ]; /** * 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(User::class, Member::class) ->withPivot([ 'id', 'role', 'billable_rate', ]) ->withTimestamps() ->as('membership'); } /** * Get the owner of the team. * * @return BelongsTo */ public function owner(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } /** * @return HasMany */ public function members(): HasMany { return $this->hasMany(Member::class); } /** * @return BelongsToMany */ public function realUsers(): BelongsToMany { return $this->users() ->where('is_placeholder', false); } /** * This method prevents an unhandled exception when the ID is not a UUID. * Normally this can be fixed with a route pattern, but Jetstream does not use route model binding. * * @param array $columns */ public function findOrFail(string $id, array $columns = ['*']): \Laravel\Jetstream\Team { if (! Str::isUuid($id)) { throw (new ModelNotFoundException)->setModel( self::class, $id ); } return parent::findOrFail($id, $columns); } }