$notifications * @property-read int|null $notifications_count * @property-read Team $team * * @method static Builder|TeamInvite findByPlainToken(string $token) * @method static Builder|TeamInvite newModelQuery() * @method static Builder|TeamInvite newQuery() * @method static Builder|TeamInvite query() * @method static Builder|TeamInvite whereCreatedAt($value) * @method static Builder|TeamInvite whereId($value) * @method static Builder|TeamInvite whereInviteToken($value) * @method static Builder|TeamInvite whereInvitedByUserId($value) * @method static Builder|TeamInvite whereInvitedEmail($value) * @method static Builder|TeamInvite whereTeamId($value) * @method static Builder|TeamInvite whereUpdatedAt($value) * * @mixin \Eloquent */ #[Fillable(['team_id', 'invited_by_user_id', 'invited_email'])] class TeamInvite extends Model { use Notifiable; protected ?string $plainInviteToken = null; protected static function booted(): void { self::creating(function (self $model) { $model->plainInviteToken = Str::random(128); $hashedToken = hash('sha256', $model->plainInviteToken); $model->invite_token = $hashedToken; }); self::created(function (self $model) { $model->notify(new InviteToTeam); }); } public function team(): BelongsTo { return $this->belongsTo(Team::class); } public function invitedBy(): BelongsTo { return $this->belongsTo(User::class, 'invited_by_user_id'); } public function plainInviteToken(): ?string { return $this->plainInviteToken; } /** * Route notifications for the mail channel. * * @return array|string */ public function routeNotificationForMail(Notification $notification): array|string { return $this->invited_email; } #[Scope] protected function findByPlainToken(Builder $query, string $token): Builder { return $query->where('invite_token', hash('sha256', $token)); } }