Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s

- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-25 20:35:30 +00:00
parent 7197eaebf2
commit 9c0f8de791
15771 changed files with 1564103 additions and 5 deletions

View file

@ -0,0 +1,32 @@
<?php
namespace Illuminate\Notifications;
class Action
{
/**
* The action text.
*
* @var string
*/
public $text;
/**
* The action URL.
*
* @var string
*/
public $url;
/**
* Create a new action instance.
*
* @param string $text
* @param string $url
*/
public function __construct($text, $url)
{
$this->url = $url;
$this->text = $text;
}
}

View file

@ -0,0 +1,79 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Contracts\Notifications\Dispatcher;
use InvalidArgumentException;
class AnonymousNotifiable
{
/**
* All of the notification routing information.
*
* @var array
*/
public $routes = [];
/**
* Add routing information to the target.
*
* @param string $channel
* @param mixed $route
* @return $this
*
* @throws \InvalidArgumentException
*/
public function route($channel, $route)
{
if ($channel === 'database') {
throw new InvalidArgumentException('The database channel does not support on-demand notifications.');
}
$this->routes[$channel] = $route;
return $this;
}
/**
* Send the given notification.
*
* @param mixed $notification
* @return void
*/
public function notify($notification)
{
app(Dispatcher::class)->send($this, $notification);
}
/**
* Send the given notification immediately.
*
* @param mixed $notification
* @return void
*/
public function notifyNow($notification)
{
app(Dispatcher::class)->sendNow($this, $notification);
}
/**
* Get the notification routing information for the given driver.
*
* @param string $driver
* @return mixed
*/
public function routeNotificationFor($driver)
{
return $this->routes[$driver] ?? null;
}
/**
* Get the value of the notifiable's primary key.
*
* @return mixed
*/
public function getKey()
{
//
}
}

View file

@ -0,0 +1,192 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Contracts\Bus\Dispatcher as Bus;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Notifications\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Notifications\Factory as FactoryContract;
use Illuminate\Support\Manager;
use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
class ChannelManager extends Manager implements DispatcherContract, FactoryContract
{
use Macroable, ResolvesQueueRoutes;
/**
* The resolved notification sender instance.
*
* @var \Illuminate\Notifications\NotificationSender|null
*/
protected $notificationSender;
/**
* The default channel used to deliver messages.
*
* @var string
*/
protected $defaultChannel = 'mail';
/**
* The locale used when sending notifications.
*
* @var string|null
*/
protected $locale;
/**
* Send the given notification to the given notifiable entities.
*
* @param \Illuminate\Support\Collection|mixed $notifiables
* @param mixed $notification
* @return void
*/
public function send($notifiables, $notification)
{
$this->resolveNotificationSender()->send($notifiables, $notification);
}
/**
* Send the given notification immediately.
*
* @param \Illuminate\Support\Collection|mixed $notifiables
* @param mixed $notification
* @param array|null $channels
* @return void
*/
public function sendNow($notifiables, $notification, ?array $channels = null)
{
$this->resolveNotificationSender()->sendNow($notifiables, $notification, $channels);
}
/**
* Get a channel instance.
*
* @param \UnitEnum|string|null $name
* @return mixed
*/
public function channel($name = null)
{
return $this->driver($name);
}
/**
* Get a driver instance.
*
* @param \UnitEnum|string|null $driver
* @return mixed
*/
public function driver($driver = null)
{
return parent::driver($driver);
}
/**
* Create an instance of the database driver.
*
* @return \Illuminate\Notifications\Channels\DatabaseChannel
*/
protected function createDatabaseDriver()
{
return $this->container->make(Channels\DatabaseChannel::class);
}
/**
* Create an instance of the broadcast driver.
*
* @return \Illuminate\Notifications\Channels\BroadcastChannel
*/
protected function createBroadcastDriver()
{
return $this->container->make(Channels\BroadcastChannel::class);
}
/**
* Create an instance of the mail driver.
*
* @return \Illuminate\Notifications\Channels\MailChannel
*/
protected function createMailDriver()
{
return $this->container->make(Channels\MailChannel::class);
}
/**
* Create a new driver instance.
*
* @param string $driver
* @return mixed
*
* @throws \InvalidArgumentException
*/
protected function createDriver($driver)
{
try {
return parent::createDriver($driver);
} catch (InvalidArgumentException $e) {
if (class_exists($driver)) {
return $this->container->make($driver);
}
throw $e;
}
}
/**
* Resolve the NotificationSender instance.
*
* @return \Illuminate\Notifications\NotificationSender
*/
protected function resolveNotificationSender()
{
return $this->notificationSender ??= new NotificationSender(
$this, $this->container->make(Bus::class), $this->container->make(Dispatcher::class), $this->locale
);
}
/**
* Get the default channel driver name.
*
* @return string
*/
public function getDefaultDriver()
{
return $this->defaultChannel;
}
/**
* Get the default channel driver name.
*
* @return string
*/
public function deliversVia()
{
return $this->getDefaultDriver();
}
/**
* Set the default channel driver name.
*
* @param string $channel
* @return void
*/
public function deliverVia($channel)
{
$this->defaultChannel = $channel;
}
/**
* Set the locale of notifications.
*
* @param string $locale
* @return $this
*/
public function locale($locale)
{
$this->locale = $locale;
return $this;
}
}

View file

@ -0,0 +1,74 @@
<?php
namespace Illuminate\Notifications\Channels;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Notifications\Events\BroadcastNotificationCreated;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;
use RuntimeException;
class BroadcastChannel
{
/**
* The event dispatcher.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* Create a new broadcast channel.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
*/
public function __construct(Dispatcher $events)
{
$this->events = $events;
}
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return array|null
*/
public function send($notifiable, Notification $notification)
{
$message = $this->getData($notifiable, $notification);
$event = new BroadcastNotificationCreated(
$notifiable, $notification, is_array($message) ? $message : $message->data
);
if ($message instanceof BroadcastMessage) {
$event->onConnection($message->connection)
->onQueue($message->queue);
}
return $this->events->dispatch($event);
}
/**
* Get the data for the notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return mixed
*
* @throws \RuntimeException
*/
protected function getData($notifiable, Notification $notification)
{
if (method_exists($notification, 'toBroadcast')) {
return $notification->toBroadcast($notifiable);
}
if (method_exists($notification, 'toArray')) {
return $notification->toArray($notifiable);
}
throw new RuntimeException('Notification is missing toBroadcast / toArray method.');
}
}

View file

@ -0,0 +1,68 @@
<?php
namespace Illuminate\Notifications\Channels;
use Illuminate\Notifications\Notification;
use RuntimeException;
class DatabaseChannel
{
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return \Illuminate\Database\Eloquent\Model
*/
public function send($notifiable, Notification $notification)
{
return $notifiable->routeNotificationFor('database', $notification)->create(
$this->buildPayload($notifiable, $notification)
);
}
/**
* Build an array payload for the DatabaseNotification Model.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return array
*/
protected function buildPayload($notifiable, Notification $notification)
{
return [
'id' => $notification->id,
'type' => method_exists($notification, 'databaseType')
? $notification->databaseType($notifiable)
: get_class($notification),
'data' => $this->getData($notifiable, $notification),
'read_at' => method_exists($notification, 'initialDatabaseReadAtValue')
? $notification->initialDatabaseReadAtValue($notifiable)
: null,
];
}
/**
* Get the data for the notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return array
*
* @throws \RuntimeException
*/
protected function getData($notifiable, Notification $notification)
{
if (method_exists($notification, 'toDatabase')) {
return is_array($data = $notification->toDatabase($notifiable))
? $data
: $data->data;
}
if (method_exists($notification, 'toArray')) {
return $notification->toArray($notifiable);
}
throw new RuntimeException('Notification is missing toDatabase / toArray method.');
}
}

View file

@ -0,0 +1,307 @@
<?php
namespace Illuminate\Notifications\Channels;
use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Container\Container;
use Illuminate\Contracts\Mail\Factory as MailFactory;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Markdown;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Symfony\Component\Mailer\Header\MetadataHeader;
use Symfony\Component\Mailer\Header\TagHeader;
class MailChannel
{
/**
* The mailer implementation.
*
* @var \Illuminate\Contracts\Mail\Factory
*/
protected $mailer;
/**
* The markdown implementation.
*
* @var \Illuminate\Mail\Markdown
*/
protected $markdown;
/**
* Create a new mail channel instance.
*
* @param \Illuminate\Contracts\Mail\Factory $mailer
* @param \Illuminate\Mail\Markdown $markdown
*/
public function __construct(MailFactory $mailer, Markdown $markdown)
{
$this->mailer = $mailer;
$this->markdown = $markdown;
}
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return \Illuminate\Mail\SentMessage|null
*/
public function send($notifiable, Notification $notification)
{
$message = $notification->toMail($notifiable);
if (! $notifiable->routeNotificationFor('mail', $notification) &&
! $message instanceof Mailable) {
return;
}
if ($message instanceof Mailable) {
return $message->send($this->mailer);
}
return $this->mailer->mailer($message->mailer ?? null)->send(
$this->buildView($message),
array_merge($message->data(), $this->additionalMessageData($notification)),
$this->messageBuilder($notifiable, $notification, $message)
);
}
/**
* Get the mailer Closure for the message.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return \Closure
*/
protected function messageBuilder($notifiable, $notification, $message)
{
return function ($mailMessage) use ($notifiable, $notification, $message) {
$this->buildMessage($mailMessage, $notifiable, $notification, $message);
};
}
/**
* Build the notification's view.
*
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return string|array
*/
protected function buildView($message)
{
if ($message->view) {
return $message->view;
}
return [
'html' => $this->buildMarkdownHtml($message),
'text' => $this->buildMarkdownText($message),
];
}
/**
* Build the HTML view for a Markdown message.
*
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return \Closure
*/
protected function buildMarkdownHtml($message)
{
return fn ($data) => $this->markdownRenderer($message)->render(
$message->markdown, array_merge($data, $message->data()),
);
}
/**
* Build the text view for a Markdown message.
*
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return \Closure
*/
protected function buildMarkdownText($message)
{
return fn ($data) => $this->markdownRenderer($message)->renderText(
$message->markdown, array_merge($data, $message->data()),
);
}
/**
* Get the Markdown implementation.
*
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return \Illuminate\Mail\Markdown
*/
protected function markdownRenderer($message)
{
$config = Container::getInstance()->get(ConfigRepository::class);
$theme = $message->theme ?? $config->get('mail.markdown.theme', 'default');
return $this->markdown->theme($theme);
}
/**
* Get additional meta-data to pass along with the view data.
*
* @param \Illuminate\Notifications\Notification $notification
* @return array
*/
protected function additionalMessageData($notification)
{
return [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
'__laravel_notification_queued' => in_array(
ShouldQueue::class,
class_implements($notification)
),
];
}
/**
* Build the mail message.
*
* @param \Illuminate\Mail\Message $mailMessage
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return void
*/
protected function buildMessage($mailMessage, $notifiable, $notification, $message)
{
$this->addressMessage($mailMessage, $notifiable, $notification, $message);
$mailMessage->subject($message->subject ?: Str::title(
Str::snake(class_basename($notification), ' ')
));
$this->addAttachments($mailMessage, $message);
if (! is_null($message->priority)) {
$mailMessage->priority($message->priority);
}
if ($message->tags) {
foreach ($message->tags as $tag) {
$mailMessage->getHeaders()->add(new TagHeader($tag));
}
}
if ($message->metadata) {
foreach ($message->metadata as $key => $value) {
$mailMessage->getHeaders()->add(new MetadataHeader($key, $value));
}
}
$this->runCallbacks($mailMessage, $message);
}
/**
* Address the mail message.
*
* @param \Illuminate\Mail\Message $mailMessage
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return void
*/
protected function addressMessage($mailMessage, $notifiable, $notification, $message)
{
$this->addSender($mailMessage, $message);
$mailMessage->to($this->getRecipients($notifiable, $notification, $message));
if (! empty($message->cc)) {
foreach ($message->cc as $cc) {
$mailMessage->cc($cc[0], Arr::get($cc, 1));
}
}
if (! empty($message->bcc)) {
foreach ($message->bcc as $bcc) {
$mailMessage->bcc($bcc[0], Arr::get($bcc, 1));
}
}
}
/**
* Add the "from" and "reply to" addresses to the message.
*
* @param \Illuminate\Mail\Message $mailMessage
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return void
*/
protected function addSender($mailMessage, $message)
{
if (! empty($message->from)) {
$mailMessage->from($message->from[0], Arr::get($message->from, 1));
}
if (! empty($message->replyTo)) {
foreach ($message->replyTo as $replyTo) {
$mailMessage->replyTo($replyTo[0], Arr::get($replyTo, 1));
}
}
}
/**
* Get the recipients of the given message.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return mixed
*/
protected function getRecipients($notifiable, $notification, $message)
{
if (is_string($recipients = $notifiable->routeNotificationFor('mail', $notification))) {
$recipients = [$recipients];
}
return (new Collection($recipients))
->mapWithKeys(function ($recipient, $email) {
return is_numeric($email)
? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
: [$email => $recipient];
})
->all();
}
/**
* Add the attachments to the message.
*
* @param \Illuminate\Mail\Message $mailMessage
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return void
*/
protected function addAttachments($mailMessage, $message)
{
foreach ($message->attachments as $attachment) {
$mailMessage->attach($attachment['file'], $attachment['options']);
}
foreach ($message->rawAttachments as $attachment) {
$mailMessage->attachData($attachment['data'], $attachment['name'], $attachment['options']);
}
}
/**
* Run the callbacks for the message.
*
* @param \Illuminate\Mail\Message $mailMessage
* @param \Illuminate\Notifications\Messages\MailMessage $message
* @return $this
*/
protected function runCallbacks($mailMessage, $message)
{
foreach ($message->callbacks as $callback) {
$callback($mailMessage->getSymfonyMessage());
}
return $this;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Illuminate\Notifications\Console;
use Illuminate\Console\MigrationGeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand(name: 'make:notifications-table', aliases: ['notifications:table'])]
class NotificationTableCommand extends MigrationGeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:notifications-table';
/**
* The console command name aliases.
*
* @var string[]
*/
protected $aliases = ['notifications:table'];
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a migration for the notifications table';
/**
* Get the migration table name.
*
* @return string
*/
protected function migrationTableName()
{
return 'notifications';
}
/**
* Get the path to the migration stub file.
*
* @return string
*/
protected function migrationStubFile()
{
return __DIR__.'/stubs/notifications.stub';
}
}

View file

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};

View file

@ -0,0 +1,132 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\HasCollection;
use Illuminate\Database\Eloquent\Model;
class DatabaseNotification extends Model
{
/** @use HasCollection<DatabaseNotificationCollection> */
use HasCollection;
/**
* The "type" of the primary key ID.
*
* @var string
*/
protected $keyType = 'string';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'notifications';
/**
* The guarded attributes on the model.
*
* @var array<string>
*/
protected $guarded = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'data' => 'array',
'read_at' => 'datetime',
];
/**
* The type of collection that should be used for the model.
*/
protected static string $collectionClass = DatabaseNotificationCollection::class;
/**
* Get the notifiable entity that the notification belongs to.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo<\Illuminate\Database\Eloquent\Model, $this>
*/
public function notifiable()
{
return $this->morphTo();
}
/**
* Mark the notification as read.
*
* @return void
*/
public function markAsRead()
{
if (is_null($this->read_at)) {
$this->forceFill(['read_at' => $this->freshTimestamp()])->save();
}
}
/**
* Mark the notification as unread.
*
* @return void
*/
public function markAsUnread()
{
if (! is_null($this->read_at)) {
$this->forceFill(['read_at' => null])->save();
}
}
/**
* Determine if a notification has been read.
*
* @return bool
*/
public function read()
{
return $this->read_at !== null;
}
/**
* Determine if a notification has not been read.
*
* @return bool
*/
public function unread()
{
return $this->read_at === null;
}
/**
* Scope a query to only include read notifications.
*
* @param \Illuminate\Database\Eloquent\Builder<static> $query
* @return \Illuminate\Database\Eloquent\Builder<static>
*/
public function scopeRead(Builder $query)
{
return $query->whereNotNull('read_at');
}
/**
* Scope a query to only include unread notifications.
*
* @param \Illuminate\Database\Eloquent\Builder<static> $query
* @return \Illuminate\Database\Eloquent\Builder<static>
*/
public function scopeUnread(Builder $query)
{
return $query->whereNull('read_at');
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
/**
* @template TKey of array-key
* @template TModel of DatabaseNotification
*
* @extends \Illuminate\Database\Eloquent\Collection<TKey, TModel>
*/
class DatabaseNotificationCollection extends EloquentCollection
{
/**
* Mark all notifications as read.
*
* @return void
*/
public function markAsRead()
{
$this->each->markAsRead();
}
/**
* Mark all notifications as unread.
*
* @return void
*/
public function markAsUnread()
{
$this->each->markAsUnread();
}
}

View file

@ -0,0 +1,114 @@
<?php
namespace Illuminate\Notifications\Events;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
class BroadcastNotificationCreated implements ShouldBroadcast
{
use Queueable, SerializesModels;
/**
* Create a new event instance.
*
* @param mixed $notifiable The notifiable entity who received the notification.
* @param \Illuminate\Notifications\Notification $notification The notification instance.
* @param array $data The notification data.
*/
public function __construct(
public $notifiable,
public $notification,
public $data = [],
) {
}
/**
* Get the channels the event should broadcast on.
*
* @return array
*/
public function broadcastOn()
{
if ($this->notifiable instanceof AnonymousNotifiable &&
$this->notifiable->routeNotificationFor('broadcast')) {
$channels = Arr::wrap($this->notifiable->routeNotificationFor('broadcast'));
} else {
$channels = $this->notification->broadcastOn();
}
if (! empty($channels)) {
return $channels;
}
if (is_string($channels = $this->channelName())) {
return [new PrivateChannel($channels)];
}
return (new Collection($channels))
->map(fn ($channel) => new PrivateChannel($channel))
->all();
}
/**
* Get the broadcast channel name for the event.
*
* @return array|string
*/
protected function channelName()
{
if (method_exists($this->notifiable, 'receivesBroadcastNotificationsOn')) {
return $this->notifiable->receivesBroadcastNotificationsOn($this->notification);
}
$class = str_replace('\\', '.', get_class($this->notifiable));
return $class.'.'.$this->notifiable->getKey();
}
/**
* Get the data that should be sent with the broadcasted event.
*
* @return array
*/
public function broadcastWith()
{
if (method_exists($this->notification, 'broadcastWith')) {
return $this->notification->broadcastWith();
}
return array_merge($this->data, [
'id' => $this->notification->id,
'type' => $this->broadcastType(),
]);
}
/**
* Get the type of the notification being broadcast.
*
* @return string
*/
public function broadcastType()
{
return method_exists($this->notification, 'broadcastType')
? $this->notification->broadcastType()
: get_class($this->notification);
}
/**
* Get the event name of the notification being broadcast.
*
* @return string
*/
public function broadcastAs()
{
return method_exists($this->notification, 'broadcastAs')
? $this->notification->broadcastAs()
: __CLASS__;
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Illuminate\Notifications\Events;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
class NotificationFailed
{
use Queueable, SerializesModels;
/**
* Create a new event instance.
*
* @param mixed $notifiable The notifiable entity who received the notification.
* @param \Illuminate\Notifications\Notification $notification The notification instance.
* @param string $channel The channel name.
* @param array $data The data needed to process this failure.
*/
public function __construct(
public $notifiable,
public $notification,
public $channel,
public $data = [],
) {
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Illuminate\Notifications\Events;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
class NotificationSending
{
use Queueable, SerializesModels;
/**
* Create a new event instance.
*
* @param mixed $notifiable The notifiable entity who received the notification.
* @param \Illuminate\Notifications\Notification $notification The notification instance.
* @param string $channel The channel name.
*/
public function __construct(
public $notifiable,
public $notification,
public $channel,
) {
}
}

View file

@ -0,0 +1,27 @@
<?php
namespace Illuminate\Notifications\Events;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
class NotificationSent
{
use Queueable, SerializesModels;
/**
* Create a new event instance.
*
* @param mixed $notifiable The notifiable entity who received the notification.
* @param \Illuminate\Notifications\Notification $notification The notification instance.
* @param string $channel The channel name.
* @param mixed $response The channel's response.
*/
public function __construct(
public $notifiable,
public $notification,
public $channel,
public $response = null,
) {
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Illuminate\Notifications\Events;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
class NotificationSkipped
{
use Queueable, SerializesModels;
/**
* Create a new event instance.
*
* @param mixed $notifiable The notifiable entity who would have received the notification.
* @param \Illuminate\Notifications\Notification $notification The notification instance.
* @param string $channel The channel name.
*/
public function __construct(
public $notifiable,
public $notification,
public $channel,
) {
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Illuminate\Notifications;
trait HasDatabaseNotifications
{
/**
* Get the entity's notifications.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<DatabaseNotification, $this>
*/
public function notifications()
{
return $this->morphMany(DatabaseNotification::class, 'notifiable')->latest();
}
/**
* Get the entity's read notifications.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<DatabaseNotification, $this>
*/
public function readNotifications()
{
return $this->notifications()->read();
}
/**
* Get the entity's unread notifications.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<DatabaseNotification, $this>
*/
public function unreadNotifications()
{
return $this->notifications()->unread();
}
}

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Taylor Otwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,40 @@
<?php
namespace Illuminate\Notifications\Messages;
use Illuminate\Bus\Queueable;
class BroadcastMessage
{
use Queueable;
/**
* The data for the notification.
*
* @var array
*/
public $data;
/**
* Create a new message instance.
*
* @param array $data
*/
public function __construct(array $data)
{
$this->data = $data;
}
/**
* Set the message data.
*
* @param array $data
* @return $this
*/
public function data($data)
{
$this->data = $data;
return $this;
}
}

View file

@ -0,0 +1,23 @@
<?php
namespace Illuminate\Notifications\Messages;
class DatabaseMessage
{
/**
* The data that should be stored with the notification.
*
* @var array
*/
public $data = [];
/**
* Create a new database message.
*
* @param array $data
*/
public function __construct(array $data = [])
{
$this->data = $data;
}
}

View file

@ -0,0 +1,460 @@
<?php
namespace Illuminate\Notifications\Messages;
use Illuminate\Container\Container;
use Illuminate\Contracts\Mail\Attachable;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Markdown;
use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Conditionable;
class MailMessage extends SimpleMessage implements Renderable
{
use Conditionable;
/**
* The view to be rendered.
*
* @var array|string
*/
public $view;
/**
* The view data for the message.
*
* @var array
*/
public $viewData = [];
/**
* The Markdown template to render (if applicable).
*
* @var string|null
*/
public $markdown = 'notifications::email';
/**
* The current theme being used when generating emails.
*
* @var string|null
*/
public $theme;
/**
* The "from" information for the message.
*
* @var array
*/
public $from = [];
/**
* The "reply to" information for the message.
*
* @var array
*/
public $replyTo = [];
/**
* The "cc" information for the message.
*
* @var array
*/
public $cc = [];
/**
* The "bcc" information for the message.
*
* @var array
*/
public $bcc = [];
/**
* The attachments for the message.
*
* @var array
*/
public $attachments = [];
/**
* The raw attachments for the message.
*
* @var array
*/
public $rawAttachments = [];
/**
* The tags for the message.
*
* @var array
*/
public $tags = [];
/**
* The metadata for the message.
*
* @var array
*/
public $metadata = [];
/**
* Priority level of the message.
*
* @var int
*/
public $priority;
/**
* The callbacks for the message.
*
* @var array
*/
public $callbacks = [];
/**
* Set the view for the mail message.
*
* @param array|string $view
* @param array $data
* @return $this
*/
public function view($view, array $data = [])
{
$this->view = $view;
$this->viewData = $data;
$this->markdown = null;
return $this;
}
/**
* Set the plain text view for the mail message.
*
* @param string $textView
* @param array $data
* @return $this
*/
public function text($textView, array $data = [])
{
return $this->view([
'html' => is_array($this->view) ? ($this->view['html'] ?? null) : $this->view,
'text' => $textView,
], $data);
}
/**
* Set the Markdown template for the notification.
*
* @param string $view
* @param array $data
* @return $this
*/
public function markdown($view, array $data = [])
{
$this->markdown = $view;
$this->viewData = $data;
$this->view = null;
return $this;
}
/**
* Set the default markdown template.
*
* @param string $template
* @return $this
*/
public function template($template)
{
$this->markdown = $template;
return $this;
}
/**
* Set the theme to use with the Markdown template.
*
* @param string $theme
* @return $this
*/
public function theme($theme)
{
$this->theme = $theme;
return $this;
}
/**
* Set the from address for the mail message.
*
* @param string $address
* @param string|null $name
* @return $this
*/
public function from($address, $name = null)
{
$this->from = [$address, $name];
return $this;
}
/**
* Set the "reply to" address of the message.
*
* @param array|string $address
* @param string|null $name
* @return $this
*/
public function replyTo($address, $name = null)
{
if ($this->arrayOfAddresses($address)) {
$this->replyTo = array_merge($this->replyTo, $this->parseAddresses($address));
} else {
$this->replyTo[] = [$address, $name];
}
return $this;
}
/**
* Set the cc address for the mail message.
*
* @param array|string $address
* @param string|null $name
* @return $this
*/
public function cc($address, $name = null)
{
if ($this->arrayOfAddresses($address)) {
$this->cc = array_merge($this->cc, $this->parseAddresses($address));
} else {
$this->cc[] = [$address, $name];
}
return $this;
}
/**
* Set the bcc address for the mail message.
*
* @param array|string $address
* @param string|null $name
* @return $this
*/
public function bcc($address, $name = null)
{
if ($this->arrayOfAddresses($address)) {
$this->bcc = array_merge($this->bcc, $this->parseAddresses($address));
} else {
$this->bcc[] = [$address, $name];
}
return $this;
}
/**
* Attach a file to the message.
*
* @param string|\Illuminate\Contracts\Mail\Attachable|\Illuminate\Mail\Attachment $file
* @param array $options
* @return $this
*/
public function attach($file, array $options = [])
{
if ($file instanceof Attachable) {
$file = $file->toMailAttachment();
}
if ($file instanceof Attachment) {
return $file->attachTo($this);
}
$this->attachments[] = ['file' => $file, 'options' => $options];
return $this;
}
/**
* Attach multiple files to the message.
*
* @param array<string|\Illuminate\Contracts\Mail\Attachable|\Illuminate\Mail\Attachment|array> $files
* @return $this
*/
public function attachMany($files)
{
foreach ($files as $file => $options) {
if (is_int($file)) {
$this->attach($options);
} else {
$this->attach($file, $options);
}
}
return $this;
}
/**
* Attach in-memory data as an attachment.
*
* @param string $data
* @param string $name
* @param array $options
* @return $this
*/
public function attachData($data, $name, array $options = [])
{
$this->rawAttachments[] = ['data' => $data, 'name' => $name, 'options' => $options];
return $this;
}
/**
* Attach a file to the message from storage.
*
* @param string $path
* @param string|null $name
* @param array $options
* @return $this
*/
public function attachFromStorage($path, $name = null, array $options = [])
{
return $this->attachFromStorageDisk(null, $path, $name, $options);
}
/**
* Attach a file to the message from storage.
*
* @param string|null $disk
* @param string $path
* @param string|null $name
* @param array $options
* @return $this
*/
public function attachFromStorageDisk($disk, $path, $name = null, array $options = [])
{
$attachment = Attachment::fromStorageDisk($disk, $path);
if (! is_null($name)) {
$attachment->as($name);
}
if (isset($options['mime'])) {
$attachment->withMime($options['mime']);
}
return $this->attach($attachment);
}
/**
* Add a tag header to the message when supported by the underlying transport.
*
* @param string $value
* @return $this
*/
public function tag($value)
{
$this->tags[] = $value;
return $this;
}
/**
* Add a metadata header to the message when supported by the underlying transport.
*
* @param string $key
* @param string $value
* @return $this
*/
public function metadata($key, $value)
{
$this->metadata[$key] = $value;
return $this;
}
/**
* Set the priority of this message.
*
* The value is an integer where 1 is the highest priority and 5 is the lowest.
*
* @param int $level
* @return $this
*/
public function priority($level)
{
$this->priority = $level;
return $this;
}
/**
* Get the data array for the mail message.
*
* @return array
*/
public function data()
{
return array_merge($this->toArray(), $this->viewData);
}
/**
* Parse the multi-address array into the necessary format.
*
* @param array $value
* @return array
*/
protected function parseAddresses($value)
{
return (new Collection($value))
->map(fn ($address, $name) => [$address, is_numeric($name) ? null : $name])
->values()
->all();
}
/**
* Determine if the given "address" is actually an array of addresses.
*
* @param mixed $address
* @return bool
*/
protected function arrayOfAddresses($address)
{
return is_iterable($address) || $address instanceof Arrayable;
}
/**
* Render the mail notification message into an HTML string.
*
* @return \Illuminate\Support\HtmlString
*/
public function render()
{
if (isset($this->view)) {
return Container::getInstance()->make('mailer')->render(
$this->view, $this->data()
);
}
$markdown = Container::getInstance()->make(Markdown::class);
return $markdown->theme($this->theme ?: $markdown->getTheme())
->render($this->markdown, $this->data());
}
/**
* Register a callback to be called with the Symfony message instance.
*
* @param callable $callback
* @return $this
*/
public function withSymfonyMessage($callback)
{
$this->callbacks[] = $callback;
return $this;
}
}

View file

@ -0,0 +1,292 @@
<?php
namespace Illuminate\Notifications\Messages;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Notifications\Action;
class SimpleMessage
{
/**
* The "level" of the notification (info, success, error).
*
* @var string
*/
public $level = 'info';
/**
* The subject of the notification.
*
* @var string
*/
public $subject;
/**
* The notification's greeting.
*
* @var string
*/
public $greeting;
/**
* The notification's salutation.
*
* @var string
*/
public $salutation;
/**
* The "intro" lines of the notification.
*
* @var array
*/
public $introLines = [];
/**
* The "outro" lines of the notification.
*
* @var array
*/
public $outroLines = [];
/**
* The text / label for the action.
*
* @var string
*/
public $actionText;
/**
* The action URL.
*
* @var string
*/
public $actionUrl;
/**
* The name of the mailer that should send the notification.
*
* @var string
*/
public $mailer;
/**
* Indicate that the notification gives information about a successful operation.
*
* @return $this
*/
public function success()
{
$this->level = 'success';
return $this;
}
/**
* Indicate that the notification gives information about an error.
*
* @return $this
*/
public function error()
{
$this->level = 'error';
return $this;
}
/**
* Set the "level" of the notification (success, error, etc.).
*
* @param string $level
* @return $this
*/
public function level($level)
{
$this->level = $level;
return $this;
}
/**
* Set the subject of the notification.
*
* @param string $subject
* @return $this
*/
public function subject($subject)
{
$this->subject = $subject;
return $this;
}
/**
* Set the greeting of the notification.
*
* @param string $greeting
* @return $this
*/
public function greeting($greeting)
{
$this->greeting = $greeting;
return $this;
}
/**
* Set the salutation of the notification.
*
* @param string $salutation
* @return $this
*/
public function salutation($salutation)
{
$this->salutation = $salutation;
return $this;
}
/**
* Add a line of text to the notification.
*
* @param mixed $line
* @return $this
*/
public function line($line)
{
return $this->with($line);
}
/**
* Add a line of text to the notification if the given condition is true.
*
* @param bool $boolean
* @param mixed $line
* @return $this
*/
public function lineIf($boolean, $line)
{
if ($boolean) {
return $this->line($line);
}
return $this;
}
/**
* Add lines of text to the notification.
*
* @param iterable $lines
* @return $this
*/
public function lines($lines)
{
foreach ($lines as $line) {
$this->line($line);
}
return $this;
}
/**
* Add lines of text to the notification if the given condition is true.
*
* @param bool $boolean
* @param iterable $lines
* @return $this
*/
public function linesIf($boolean, $lines)
{
if ($boolean) {
return $this->lines($lines);
}
return $this;
}
/**
* Add a line of text to the notification.
*
* @param mixed $line
* @return $this
*/
public function with($line)
{
if ($line instanceof Action) {
$this->action($line->text, $line->url);
} elseif (! $this->actionText) {
$this->introLines[] = $this->formatLine($line);
} else {
$this->outroLines[] = $this->formatLine($line);
}
return $this;
}
/**
* Format the given line of text.
*
* @param \Illuminate\Contracts\Support\Htmlable|string|array|null $line
* @return \Illuminate\Contracts\Support\Htmlable|string
*/
protected function formatLine($line)
{
if ($line instanceof Htmlable) {
return $line;
}
if (is_array($line)) {
return implode(' ', array_map(trim(...), $line));
}
return trim(implode(' ', array_map(trim(...), preg_split('/\\r\\n|\\r|\\n/', $line ?? ''))));
}
/**
* Configure the "call to action" button.
*
* @param string $text
* @param string $url
* @return $this
*/
public function action($text, $url)
{
$this->actionText = $text;
$this->actionUrl = $url;
return $this;
}
/**
* Set the name of the mailer that should send the notification.
*
* @param string $mailer
* @return $this
*/
public function mailer($mailer)
{
$this->mailer = $mailer;
return $this;
}
/**
* Get an array representation of the message.
*
* @return array
*/
public function toArray()
{
return [
'level' => $this->level,
'subject' => $this->subject,
'greeting' => $this->greeting,
'salutation' => $this->salutation,
'introLines' => $this->introLines,
'outroLines' => $this->outroLines,
'actionText' => $this->actionText,
'actionUrl' => $this->actionUrl,
'displayableActionUrl' => str_replace(['mailto:', 'tel:'], '', $this->actionUrl ?? ''),
];
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace Illuminate\Notifications;
trait Notifiable
{
use HasDatabaseNotifications, RoutesNotifications;
}

View file

@ -0,0 +1,47 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Queue\SerializesModels;
class Notification
{
use SerializesModels;
/**
* The unique identifier for the notification.
*
* @var string
*/
public $id;
/**
* The locale to be used when sending the notification.
*
* @var string|null
*/
public $locale;
/**
* Get the channels the event should broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return [];
}
/**
* Set the locale to send this notification in.
*
* @param string $locale
* @return $this
*/
public function locale($locale)
{
$this->locale = $locale;
return $this;
}
}

View file

@ -0,0 +1,317 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Translation\HasLocalePreference;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Events\NotificationFailed;
use Illuminate\Notifications\Events\NotificationSending;
use Illuminate\Notifications\Events\NotificationSent;
use Illuminate\Notifications\Events\NotificationSkipped;
use Illuminate\Queue\Attributes\Connection;
use Illuminate\Queue\Attributes\Delay;
use Illuminate\Queue\Attributes\Queue as QueueAttribute;
use Illuminate\Queue\Attributes\ReadsQueueAttributes;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Localizable;
use Symfony\Component\Mailer\Exception\HttpTransportException;
use Symfony\Component\Mailer\Exception\TransportException;
use Throwable;
class NotificationSender
{
use Localizable, ReadsQueueAttributes;
/**
* The notification manager instance.
*
* @var \Illuminate\Notifications\ChannelManager
*/
protected $manager;
/**
* The Bus dispatcher instance.
*
* @var \Illuminate\Contracts\Bus\Dispatcher
*/
protected $bus;
/**
* The event dispatcher.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* The locale to be used when sending notifications.
*
* @var string|null
*/
protected $locale;
/**
* Indicates whether a NotificationFailed event has been dispatched.
*
* @var bool
*/
protected $failedEventWasDispatched = false;
/**
* Create a new notification sender instance.
*
* @param \Illuminate\Notifications\ChannelManager $manager
* @param \Illuminate\Contracts\Bus\Dispatcher $bus
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @param string|null $locale
*/
public function __construct($manager, $bus, $events, $locale = null)
{
$this->bus = $bus;
$this->events = $events;
$this->locale = $locale;
$this->manager = $manager;
$this->events->listen(NotificationFailed::class, fn () => $this->failedEventWasDispatched = true);
}
/**
* Send the given notification to the given notifiable entities.
*
* @param \Illuminate\Support\Collection|mixed $notifiables
* @param mixed $notification
* @return void
*/
public function send($notifiables, $notification)
{
if ($notification instanceof ShouldQueue) {
return $this->queueNotification($notifiables, $notification);
}
$this->sendNow($notifiables, $notification);
}
/**
* Send the given notification immediately.
*
* @param \Illuminate\Support\Collection|mixed $notifiables
* @param mixed $notification
* @param array|null $channels
* @return void
*/
public function sendNow($notifiables, $notification, ?array $channels = null)
{
$notifiables = $this->formatNotifiables($notifiables);
$original = clone $notification;
foreach ($notifiables as $notifiable) {
if (empty($viaChannels = $channels ?: $original->via($notifiable))) {
continue;
}
$this->withLocale($this->preferredLocale($notifiable, $original), function () use ($viaChannels, $notifiable, $original) {
$notificationId = (string) Str::uuid();
foreach ((array) $viaChannels as $channel) {
if (! ($notifiable instanceof AnonymousNotifiable && $channel === 'database')) {
$this->sendToNotifiable($notifiable, $notificationId, clone $original, $channel);
}
}
});
}
}
/**
* Get the notifiable's preferred locale for the notification.
*
* @param mixed $notifiable
* @param mixed $notification
* @return string|null
*/
protected function preferredLocale($notifiable, $notification)
{
return $notification->locale ?? $this->locale ?? value(function () use ($notifiable) {
if ($notifiable instanceof HasLocalePreference) {
return $notifiable->preferredLocale();
}
});
}
/**
* Send the given notification to the given notifiable via a channel.
*
* @param mixed $notifiable
* @param string $id
* @param mixed $notification
* @param string $channel
* @return void
*
* @throws \Throwable
*/
protected function sendToNotifiable($notifiable, $id, $notification, $channel)
{
if (! $notification->id) {
$notification->id = $id;
}
if (! $this->shouldSendNotification($notifiable, $notification, $channel)) {
$this->events->dispatch(
new NotificationSkipped($notifiable, $notification, $channel)
);
return;
}
try {
$response = $this->manager->driver($channel)->send($notifiable, $notification);
} catch (Throwable $exception) {
if (! $this->failedEventWasDispatched) {
if ($exception instanceof HttpTransportException) {
$exception = new TransportException($exception->getMessage(), $exception->getCode());
}
$this->events->dispatch(
new NotificationFailed($notifiable, $notification, $channel, ['exception' => $exception])
);
}
$this->failedEventWasDispatched = false;
throw $exception;
}
if (method_exists($notification, 'afterSending')) {
$notification->afterSending($notifiable, $channel, $response);
}
$this->events->dispatch(
new NotificationSent($notifiable, $notification, $channel, $response)
);
}
/**
* Determines if the notification can be sent.
*
* @param mixed $notifiable
* @param mixed $notification
* @param string $channel
* @return bool
*/
protected function shouldSendNotification($notifiable, $notification, $channel)
{
if (method_exists($notification, 'shouldSend') &&
$notification->shouldSend($notifiable, $channel) === false) {
return false;
}
return $this->events->until(
new NotificationSending($notifiable, $notification, $channel)
) !== false;
}
/**
* Queue the given notification instances.
*
* @param mixed $notifiables
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
protected function queueNotification($notifiables, $notification)
{
$notifiables = $this->formatNotifiables($notifiables);
$original = clone $notification;
foreach ($notifiables as $notifiable) {
$notificationId = (string) Str::uuid();
foreach ((array) $original->via($notifiable) as $channel) {
$notification = clone $original;
if (! $notification->id) {
$notification->id = $notificationId;
}
if (! is_null($this->locale)) {
$notification->locale = $this->locale;
}
$connection = $this->getAttributeValue($notification, Connection::class, 'connection')
?? $this->manager->resolveConnectionFromQueueRoute($notification)
?? null;
if (method_exists($notification, 'viaConnections')) {
$connection = $notification->viaConnections()[$channel] ?? $connection;
}
$queue = $this->getAttributeValue($notification, QueueAttribute::class, 'queue')
?? $this->manager->resolveQueueFromQueueRoute($notification)
?? null;
if (method_exists($notification, 'viaQueues')) {
$queue = $notification->viaQueues()[$channel] ?? $queue;
}
$delay = method_exists($notification, 'withDelay')
? ($notification->withDelay($notifiable, $channel) ?? null)
: $this->getAttributeValue($notification, Delay::class, 'delay');
$messageGroup = $notification->messageGroup ?? (method_exists($notification, 'messageGroup') ? $notification->messageGroup() : null);
if (method_exists($notification, 'withMessageGroups')) {
$messageGroup = $notification->withMessageGroups($notifiable, $channel) ?? null;
}
$deduplicator = $notification->deduplicator ?? (method_exists($notification, 'deduplicationId') ? $notification->deduplicationId(...) : null);
if (method_exists($notification, 'withDeduplicators')) {
$deduplicator = $notification->withDeduplicators($notifiable, $channel) ?? null;
}
$middleware = $notification->middleware ?? [];
if (method_exists($notification, 'middleware')) {
$middleware = array_merge(
$notification->middleware($notifiable, $channel),
$middleware
);
}
$this->bus->dispatch(
$this->manager->getContainer()->make(SendQueuedNotifications::class, [
'notifiables' => $notifiable,
'notification' => $notification,
'channels' => [$channel],
])
->onConnection($connection)
->onQueue($queue)
->delay(is_array($delay) ? ($delay[$channel] ?? null) : $delay)
->onGroup(is_array($messageGroup) ? ($messageGroup[$channel] ?? null) : $messageGroup)
->withDeduplicator(is_array($deduplicator) ? ($deduplicator[$channel] ?? null) : $deduplicator)
->through($middleware)
);
}
}
}
/**
* Format the notifiables into a Collection / array if necessary.
*
* @param mixed $notifiables
* @return \Illuminate\Database\Eloquent\Collection|array
*/
protected function formatNotifiables($notifiables)
{
if (! $notifiables instanceof Collection && ! is_array($notifiables)) {
return $notifiables instanceof Model
? new EloquentCollection([$notifiables])
: [$notifiables];
}
return $notifiables;
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Contracts\Notifications\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Notifications\Factory as FactoryContract;
use Illuminate\Support\ServiceProvider;
class NotificationServiceProvider extends ServiceProvider
{
/**
* Boot the application services.
*
* @return void
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/resources/views', 'notifications');
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/resources/views' => $this->app->resourcePath('views/vendor/notifications'),
], 'laravel-notifications');
}
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app->singleton(ChannelManager::class, fn ($app) => new ChannelManager($app));
$this->app->alias(
ChannelManager::class, DispatcherContract::class
);
$this->app->alias(
ChannelManager::class, FactoryContract::class
);
}
}

View file

@ -0,0 +1,52 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Contracts\Notifications\Dispatcher;
use Illuminate\Support\Str;
trait RoutesNotifications
{
/**
* Send the given notification.
*
* @param mixed $instance
* @return void
*/
public function notify($instance)
{
app(Dispatcher::class)->send($this, $instance);
}
/**
* Send the given notification immediately.
*
* @param mixed $instance
* @param array|null $channels
* @return void
*/
public function notifyNow($instance, ?array $channels = null)
{
app(Dispatcher::class)->sendNow($this, $instance, $channels);
}
/**
* Get the notification routing information for the given driver.
*
* @param string $driver
* @param \Illuminate\Notifications\Notification|null $notification
* @return mixed
*/
public function routeNotificationFor($driver, $notification = null)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}($notification);
}
return match ($driver) {
'database' => $this->notifications(),
'mail' => $this->email,
default => null,
};
}
}

View file

@ -0,0 +1,205 @@
<?php
namespace Illuminate\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Queue\Attributes\Backoff;
use Illuminate\Queue\Attributes\DeleteWhenMissingModels;
use Illuminate\Queue\Attributes\FailOnTimeout;
use Illuminate\Queue\Attributes\MaxExceptions;
use Illuminate\Queue\Attributes\ReadsQueueAttributes;
use Illuminate\Queue\Attributes\Timeout;
use Illuminate\Queue\Attributes\Tries;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Collection;
class SendQueuedNotifications implements ShouldQueue
{
use InteractsWithQueue, Queueable, ReadsQueueAttributes, SerializesModels;
/**
* The notifiable entities that should receive the notification.
*
* @var \Illuminate\Support\Collection
*/
public $notifiables;
/**
* The notification to be sent.
*
* @var \Illuminate\Notifications\Notification
*/
public $notification;
/**
* All of the channels to send the notification to.
*
* @var array
*/
public $channels;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout;
/**
* The maximum number of unhandled exceptions to allow before failing.
*
* @var int
*/
public $maxExceptions;
/**
* Indicates if the job should be encrypted.
*
* @var bool
*/
public $shouldBeEncrypted = false;
/**
* Indicates if the job should be deleted when models are missing.
*/
public bool $deleteWhenMissingModels = false;
/**
* Indicates if the job should be marked as failed on timeout.
*
* @var bool
*/
public $failOnTimeout = false;
/**
* Create a new job instance.
*
* @param \Illuminate\Notifications\Notifiable|\Illuminate\Support\Collection $notifiables
* @param \Illuminate\Notifications\Notification $notification
* @param array|null $channels
*/
public function __construct($notifiables, $notification, ?array $channels = null)
{
$this->channels = $channels;
$this->notification = $notification;
$this->notifiables = $this->wrapNotifiables($notifiables);
$this->tries = $this->getAttributeValue($notification, Tries::class, 'tries');
$this->timeout = $this->getAttributeValue($notification, Timeout::class, 'timeout');
$this->maxExceptions = $this->getAttributeValue($notification, MaxExceptions::class, 'maxExceptions');
$this->deleteWhenMissingModels = $this->getAttributeValue($notification, DeleteWhenMissingModels::class, 'deleteWhenMissingModels') ?? false;
$this->failOnTimeout = $this->getAttributeValue($notification, FailOnTimeout::class, 'failOnTimeout') ?? false;
if ($notification instanceof ShouldQueueAfterCommit) {
$this->afterCommit = true;
} else {
$this->afterCommit = property_exists($notification, 'afterCommit') ? $notification->afterCommit : null;
}
$this->shouldBeEncrypted = $notification instanceof ShouldBeEncrypted;
}
/**
* Wrap the notifiable(s) in a collection.
*
* @param \Illuminate\Notifications\Notifiable|\Illuminate\Support\Collection $notifiables
* @return \Illuminate\Support\Collection
*/
protected function wrapNotifiables($notifiables)
{
if ($notifiables instanceof Collection) {
return $notifiables;
} elseif ($notifiables instanceof Model) {
return EloquentCollection::wrap($notifiables);
}
return Collection::wrap($notifiables);
}
/**
* Send the notifications.
*
* @param \Illuminate\Notifications\ChannelManager $manager
* @return void
*/
public function handle(ChannelManager $manager)
{
$manager->sendNow($this->notifiables, $this->notification, $this->channels);
}
/**
* Get the display name for the queued job.
*
* @return string
*/
public function displayName()
{
return get_class($this->notification);
}
/**
* Call the failed method on the notification instance.
*
* @param \Throwable $e
* @return void
*/
public function failed($e)
{
if (method_exists($this->notification, 'failed')) {
$this->notification->failed($e);
}
}
/**
* Get the number of seconds before a released notification will be available.
*
* @return mixed
*/
public function backoff()
{
$backoff = $this->getAttributeValue($this->notification, Backoff::class, 'backoff');
if (method_exists($this->notification, 'backoff')) {
$backoff = $this->notification->backoff();
}
return $backoff;
}
/**
* Determine the time at which the job should timeout.
*
* @return \DateTime|null
*/
public function retryUntil()
{
if (! method_exists($this->notification, 'retryUntil') && ! isset($this->notification->retryUntil)) {
return;
}
return $this->notification->retryUntil ?? $this->notification->retryUntil();
}
/**
* Prepare the instance for cloning.
*
* @return void
*/
public function __clone()
{
$this->notifiables = clone $this->notifiables;
$this->notification = clone $this->notification;
}
}

View file

@ -0,0 +1,46 @@
{
"name": "illuminate/notifications",
"description": "The Illuminate Notifications package.",
"license": "MIT",
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"require": {
"php": "^8.3",
"illuminate/broadcasting": "^13.0",
"illuminate/bus": "^13.0",
"illuminate/collections": "^13.0",
"illuminate/conditionable": "^13.0",
"illuminate/container": "^13.0",
"illuminate/contracts": "^13.0",
"illuminate/filesystem": "^13.0",
"illuminate/mail": "^13.0",
"illuminate/queue": "^13.0",
"illuminate/support": "^13.0"
},
"suggest": {
"illuminate/database": "Required to use the database transport (^13.0)."
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Illuminate\\Notifications\\": ""
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "13.0.x-dev"
}
}
}

View file

@ -0,0 +1,58 @@
<x-mail::message>
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level === 'error')
# @lang('Whoops!')
@else
# @lang('Hello!')
@endif
@endif
{{-- Intro Lines --}}
@foreach ($introLines as $line)
{{ $line }}
@endforeach
{{-- Action Button --}}
@isset($actionText)
<?php
$color = match ($level) {
'success', 'error' => $level,
default => 'primary',
};
?>
<x-mail::button :url="$actionUrl" :color="$color">
{{ $actionText }}
</x-mail::button>
@endisset
{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}
@endforeach
{{-- Salutation --}}
@if (! empty($salutation))
{{ $salutation }}
@else
@lang('Regards,')<br>
{{ config('app.name') }}
@endif
{{-- Subcopy --}}
@isset($actionText)
<x-slot:subcopy>
@lang(
"If you're having trouble clicking the \":actionText\" button, copy and paste the URL below\n".
'into your web browser:',
[
'actionText' => $actionText,
]
) <span class="break-all">[{{ $displayableActionUrl }}]({{ $actionUrl }})</span>
</x-slot:subcopy>
@endisset
</x-mail::message>