Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Created April 24, 2025 14:50
Show Gist options
  • Save stevebauman/897926385d68d9b4cc85bbad9b0d52dc to your computer and use it in GitHub Desktop.
Save stevebauman/897926385d68d9b4cc85bbad9b0d52dc to your computer and use it in GitHub Desktop.
Notifiable Guest User | Laravel
<?php
namespace App\Support;
use Illuminate\Notifications\RoutesNotifications;
readonly class Guest
{
use RoutesNotifications;
public function __construct(
public ?string $name = null,
public ?string $email = null,
public ?string $phoneNumber = null,
) {}
public static function billing(): static
{
return new static(
name: 'Billing',
email: '[email protected]',
);
}
public static function support(): static
{
return new static(
name: 'Support',
email: '[email protected]',
phoneNumber: '+155512345678'
);
}
public function getKey(): string
{
return $this->email ?? $this->phoneNumber;
}
public function routeNotificationForMail(): ?string
{
return $this->email;
}
public function routeNotificationForTelephony(): ?string
{
return $this->phoneNumber;
}
public function routeNotificationForDatabase(): void
{
// Do nothing.
}
}
@njoguamos
Copy link

Neat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment