---
title: "DI a akcie — Webhooks for Laravel | Roundly"
description: "Bez fasády: injektujte WebhooksManager alebo zavolajte jednoúčelovú akciu — každá akcia so signatúrou execute() a metódou fasády."
url: https://roundly-consulting.com/sk/open-source/navody/webhooks-for-laravel/bez-fasady
language: sk
---

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

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

# DI a akcie

Fasáda je odporúčaná predvoľba, nie jediná cesta. RoundlyConsulting\\Webhooks\\WebhooksManager je koreň fasády — scoped väzba, ktorú môžete injektovať — a každé volanie fasády končí v jednej akcii. Všetky tri štýly spúšťajú rovnaký kód:

```php
// Send an event
Webhooks::send($endpoint, 'invoice.paid', ['invoice' => 42]);
$webhooks->send($endpoint, 'invoice.paid', ['invoice' => 42]);                       // WebhooksManager $webhooks, injected
app(SendWebhookAction::class)->execute($endpoint, 'invoice.paid', ['invoice' => 42]);

// Create an inbound endpoint
$created = Webhooks::inbound()->create(handler: 'billing');
$created = $webhooks->inbound()->create(handler: 'billing');
$created = app(CreateInboundEndpointAction::class)->execute(null, 'billing');

// Run the inbound pipeline (what the route does)
$response = Webhooks::inbound()->receive($key, $request);
$response = $webhooks->inbound()->receive($key, $request);
$response = app(ReceiveWebhookAction::class)->execute($key, $request);

// Redeliver
Webhooks::outbound()->redeliver($delivery);
$webhooks->outbound()->redeliver($delivery);
app(RedeliverWebhookAction::class)->execute($delivery);
```

## Injektovanie manažéra

```php
use RoundlyConsulting\Webhooks\Models\OutboundDelivery;
use RoundlyConsulting\Webhooks\Models\OutboundEndpoint;
use RoundlyConsulting\Webhooks\WebhooksManager;

final readonly class InvoiceWebhooks
{
    public function __construct(private WebhooksManager $webhooks) {}

    public function paid(OutboundEndpoint $endpoint, int $invoice): OutboundDelivery
    {
        return $this->webhooks->send($endpoint, 'invoice.paid', ['invoice' => $invoice], id: "invoice-{$invoice}-paid");
    }
}
```

Fake rozširuje manažér, takže pri Webhooks::fake() je fake aj injektovaný WebhooksManager. Ostatné verejné metódy manažéra (createInboundEndpoint(), rotateOutboundSecret(), redeliverFailed() a ďalšie) sú interné — volajú ich prístupy, aby fake videl každé volanie. Používajte prístupy.

## Volanie akcie

```php
use RoundlyConsulting\Webhooks\Actions\Inbound\CreateInboundEndpointAction;
use RoundlyConsulting\Webhooks\Actions\Outbound\SendWebhookAction;

app(SendWebhookAction::class)->execute($endpoint, 'invoice.paid', ['invoice' => 42]);
app(CreateInboundEndpointAction::class)->execute($team, 'billing');   // the owner comes first
```

Každá akcia určená aplikácii je final readonly, vytvára sa z kontajnera a má jednu metódu execute(). Akcie obchádzajú fake aj obmedzenie na vlastníka — pracujú s tým, čo im odovzdáte — preto ich používajte na skladanie vlastných prípadov použitia a inde fasádu alebo manažér.

## Metóda fasády → akcia

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

| Metóda fasády | Akcia | execute() |
| --- | --- | --- |
| `inbound()->create()` | `Inbound\CreateInboundEndpointAction` | `?Model $owner = null, ?string $handler = null, string $scheme = 'default', ?string $name = null, ?string $secret = null, ?InboundEndpointOptions $options = null` |
| `inbound()->update()` | `Inbound\UpdateInboundEndpointAction` | `InboundEndpoint $endpoint, InboundEndpointChanges $changes` |
| `inbound()->enable() · disable()` | `Inbound\SetInboundEndpointStateAction` | `InboundEndpoint $endpoint, bool $enabled` |
| `inbound()->delete()` | `Inbound\DeleteInboundEndpointAction` | `InboundEndpoint $endpoint` |
| `inbound()->rotateSecret()` | `Inbound\RotateInboundSecretAction` | `InboundEndpoint $endpoint, ?CarbonInterface $grace = null, ?string $secret = null` |
| `inbound()->receive()` | `Inbound\ReceiveWebhookAction` | `string $key, Request $request` |
| `inbound()->verify()` | `Inbound\VerifyInboundRequestAction` | `InboundEndpoint $endpoint, Request $request, ?string $body = null, bool $deferCommit = false` |
| `inbound()->replay()` | `Inbound\ReplayInboundDeliveryAction` | `InboundDelivery $delivery` |
| `outbound()->create()` | `Outbound\CreateOutboundEndpointAction` | `string $url, array $events = ['*'], ?string $name = null, array $headers = [], string $scheme = 'default', ?OutboundEndpointOptions $options = null, ?Model $owner = null` |
| `outbound()->update()` | `Outbound\UpdateOutboundEndpointAction` | `OutboundEndpoint $endpoint, OutboundEndpointChanges $changes` |
| `outbound()->enable() · disable()` | `Outbound\SetOutboundEndpointStateAction` | `OutboundEndpoint $endpoint, bool $enabled` |
| `outbound()->delete()` | `Outbound\DeleteOutboundEndpointAction` | `OutboundEndpoint $endpoint` |
| `outbound()->rotateSecret()` | `Outbound\RotateOutboundSecretAction` | `OutboundEndpoint $endpoint, ?CarbonInterface $grace = null` |
| `send()` | `Outbound\SendWebhookAction` | `OutboundEndpoint $endpoint, string $eventType, array\|Arrayable\|JsonSerializable $payload, ?string $id = null` |
| `broadcast() · for($owner)->broadcast()` | `Outbound\BroadcastWebhookAction` | `string $eventType, array\|Arrayable\|JsonSerializable $payload, ?Model $owner = null` |
| `outbound()->ping()` | `Outbound\PingEndpointAction` | `OutboundEndpoint $endpoint` |
| `outbound()->redeliver()` | `Outbound\RedeliverWebhookAction` | `OutboundDelivery $delivery` |
| `outbound()->redeliverFailed()` | `Outbound\RedeliverFailedDeliveriesAction` | `OutboundEndpoint $endpoint, ?CarbonInterface $since = null, bool $includeCancelled = false` |
| `outbound()->dispatchDue()` | `Outbound\DispatchDueDeliveriesAction` | — |
| `prune()` | `PruneAction` | `?PruneOptions $options = null` |

Dve poznámky: CreateInboundEndpointAction berie vlastníka ako prvý argument a VerifyInboundRequestAction prijíma aj už prečítané surové telo a $deferCommit — pri true dostanete closure commit z verdiktu, ktorý spustíte pred ďalšou akciou. AcceptInboundDeliveryAction, ProcessInboundDeliveryAction, AttemptDeliveryAction, ScheduleRetryAction, RecordEndpointFailureAction, DisableOutboundEndpointAction a CancelPendingDeliveriesAction sú interné stavebné bloky.

## 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/webhooks-for-laravel.md)
