---
title: "DI a akcie — Notifications for Laravel | Roundly"
description: "Bez fasády: injektujte NotificationsManager alebo zavolajte jednoúčelovú akciu — každá verejná akcia so signatúrou execute() a cestou cez fasádu."
url: https://roundly-consulting.com/sk/open-source/navody/notifications-for-laravel/bez-fasady
language: sk
---

[Všetky balíky](https://roundly-consulting.com/sk/open-source.md)

[Notifications for Laravel](https://roundly-consulting.com/sk/open-source/navody/notifications-for-laravel.md)

# DI a akcie

Fasáda je odporúčaná predvoľba, nie jediná cesta. Každá operácia je akcia, manažér sprístupňuje každú z nich a fasáda je skratka nad manažérom — všetky tri spúšťajú rovnaký kód. Manažér je RoundlyConsulting\\Notifications\\NotificationsManager, koreň fasády, zaregistrovaný v kontajneri ako singleton:

```php
use RoundlyConsulting\Notifications\Actions\Sending\SendNotificationAction;
use RoundlyConsulting\Notifications\DataTransferObjects\SendNotificationData;
use RoundlyConsulting\Notifications\Facades\Notifications;
use RoundlyConsulting\Notifications\NotificationsManager;
use RoundlyConsulting\Notifications\Recipients;

// 1. Facade
Notifications::send('request.awaiting_approval', $request, $approvers, ['reference' => $request->reference]);

// 2. Dependency injection — the same API, no facade
app(NotificationsManager::class)->send('request.awaiting_approval', $request, $approvers);

// 3. The raw action
app(SendNotificationAction::class)->execute(new SendNotificationData(
    type: 'request.awaiting_approval',
    subject: $request,
    recipients: Recipients::users(...$approvers),
));
```

## Injektovanie manažéra

```php
use Illuminate\Http\RedirectResponse;
use RoundlyConsulting\Notifications\NotificationsManager;
use RoundlyConsulting\Notifications\Recipients;

final class SubmitPurchaseRequestController
{
    public function __construct(private NotificationsManager $notifications) {}

    public function __invoke(PurchaseRequest $request): RedirectResponse
    {
        $request->submit();

        $this->notifications->type('request.awaiting_approval')
            ->about($request)
            ->to(Recipients::role($request->company, 'approver'))
            ->by($request->author)
            ->once("request-submitted:{$request->id}")
            ->send();

        return to_route('requests.show', $request);
    }
}
```

Manažér zámerne nie je final: fake ho rozširuje, takže kód, ktorý injektuje NotificationsManager, prejde typovou kontrolou aj pod Notifications::fake().

## Volanie akcie

```php
use RoundlyConsulting\Notifications\Actions\Inbox\MarkInboxItemReadAction;
use RoundlyConsulting\Notifications\Actions\Preferences\UpdatePreferencesAction;
use RoundlyConsulting\Notifications\Actions\Reminders\AcknowledgeAction;

// Notifications::inbox($user)->markRead($item)  ≡
app(MarkInboxItemReadAction::class)->execute($user, $item);

// Notifications::preferences($user)->update($update)  ≡
app(UpdatePreferencesAction::class)->execute($user, $update);

// Notifications::for($contract)->acknowledge('contract.expiring', by: $user)  ≡
app(AcknowledgeAction::class)->execute($contract, 'contract.expiring', $user);
```

## Metóda fasády → akcia

Menné priestory sú relatívne k RoundlyConsulting\\Notifications\\Actions:

| Akcia | execute(…) | Vracia | Cesta cez fasádu |
| --- | --- | --- | --- |
| `Sending\SendNotificationAction` | `execute(SendNotificationData)` | `SendResult` | send() · sendNotification() · type()->send() · for()->send() |
| `Inbox\MarkInboxItemReadAction` | `execute($recipient, $item)` | `InboxItem` | inbox()->markRead() |
| `Inbox\MarkInboxItemUnreadAction` | `execute($recipient, $item)` | `InboxItem` | inbox()->markUnread() |
| `Inbox\MarkAllInboxItemsReadAction` | `execute($recipient, $in, $category, $type, $withoutContext, $since)` | `int` | inbox()->markAllRead() |
| `Inbox\ArchiveInboxItemAction · UnarchiveInboxItemAction` | `execute($recipient, $item)` | `InboxItem` | inbox()->archive() · unarchive() |
| `Inbox\DeleteInboxItemAction` | `execute($recipient, $item)` | `void` | inbox()->delete() |
| `Inbox\RevokeNotificationsAction` | `execute($subject, ?$recipient)` | `int` | for()->revoke() |
| `Inbox\RecordInboxMessageAction` | `execute($recipient, InboxMessage)` | `?InboxItem` | inboxMessage() · the inbox channel |
| `Preferences\SetChannelPreferenceAction` | `execute($user, $type, list<Channel>, ?bool)` | `void` | preferences()->mute() · unmute() · set() |
| `Preferences\SetCategoryPreferenceAction` | `execute($user, $category, list<Channel>, ?bool)` | `void` | preferences()->muteCategory() · unmuteCategory() |
| `Preferences\ResetPreferencesAction` | `execute($user)` | `void` | preferences()->reset() |
| `Preferences\SetDigestPreferenceAction` | `execute($user, DigestPreferenceData)` | `void` | preferences()->digest() |
| `Preferences\SetQuietHoursAction` | `execute($user, ?QuietHours)` | `void` | preferences()->quietHours() |
| `Preferences\SetNotificationTimezoneAction` | `execute($user, ?string)` | `void` | preferences()->timezone() |
| `Preferences\UpdatePreferencesAction` | `execute($user, PreferencesUpdate)` | `void` | preferences()->update() · PATCH /preferences |
| `Delivery\DispatchDueDeliveriesAction` | `execute()` | `int` | deliveries()->dispatchDue() |
| `Digests\SendDueDigestsAction · PreviewDigestAction` | `execute() · execute($user)` | `int · ?MailMessage` | digests()->sendDue() · preview() |
| `Reminders\SyncRemindersAction` | `execute($subject, ?$type)` | `int` | for()->reminders()->sync() |
| `Reminders\ScheduleRemindersAction` | `execute($subject, $type, RecipientSpec)` | `list<NotificationReminder>` | for()->reminders()->schedule() |
| `Reminders\RemindAction` | `execute($subject, $type, ReminderRule, RecipientSpec, $data)` | `list<NotificationReminder>` | for()->remind() |
| `Reminders\CancelRemindersAction` | `execute($subject, ?$type, CancelReason)` | `int` | for()->reminders()->cancel() |
| `Reminders\AcknowledgeAction` | `execute($subject, ?$type, ?$by)` | `int` | for()->acknowledge() · reminders()->acknowledge() |
| `Reminders\FireDueRemindersAction · BackfillRemindersAction` | `execute() · execute($type)` | `FiredReminders · int` | reminders()->fireDue() · backfill() |
| `Maintenance\SweepAction · PruneNotificationsAction` | `execute(?$only) · execute()` | `SweepReport · PruneReport` | sweep() · prune() |

- Každé meniace volanie — z fasády, injektovaného manažéra, handle, fluentného buildera, traitu modelu alebo kanála inbox — prechádza manažérom, ktorý akciu vytvorí z kontajnera, takže vlastné naviazanie akcie v kontajneri platí všade.
- Notifications::fake() vymení manažéra aj v kontajneri, takže fake platí aj pre injektovaný NotificationsManager. Priame volanie akcie sa nezaznamená.
- Interné stavebné bloky — ResolveRecipientsAction, DeliverToRecipientAction, RecordInboxItemAction, QueueMailDeliveryAction, RecomputeDeferredDeliveriesAction, DeliverMailAction, ExpireStaleClaimsAction, SendDigestAction, FireReminderAction, FireEscalationAction, ApplyInteropRulesAction a ReleaseHeldInteropMailAction — nie sú určené pre kód aplikácie.

## Prejavte lásku k open source

Tento balík je zadarmo pod licenciou MIT. Ak vám šetrí čas, jednorazový príspevok alebo členstvo na Patreone nám pomôže ho ďalej udržiavať, testovať a dokumentovať.

[Ďalšie spôsoby podpory vrátane kryptomien](https://roundly-consulting.com/sk/podporte-nas.md)

Odoslaním daru súhlasíte s našimi [podmienkami prijímania darov](https://roundly-consulting.com/sk/podmienky-darov.md).

[Podporte našu open-source prácu (otvorí sa v novej karte)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Pridajte sa k nám na Patreone (otvorí sa v novej karte)](https://www.patreon.com/cw/roundly)

## Chcete to zabudovať do svojho produktu?

Naše balíky integrujeme do zákazkových Laravel a AI riešení. Napíšte nám, na čom pracujete, a ozveme sa do 48 hodín.

[Ponuka do 48 hodín](https://roundly-consulting.com/sk/kontakt.md) [Prezrieť všetky balíky](https://roundly-consulting.com/sk/open-source/navody/notifications-for-laravel.md)
