. */ declare(strict_types=1); namespace FireflyIII\Models; use FireflyIII\Support\Models\ReturnsIntegerIdTrait; use FireflyIII\User; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class WebhookMessage extends Model { use ReturnsIntegerIdTrait; protected $casts = [ 'sent' => 'boolean', 'errored' => 'boolean', 'uuid' => 'string', 'message' => 'json', 'logs' => 'json', ]; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). * * @throws NotFoundHttpException */ public static function routeBinder(string $value): self { if (auth()->check()) { $messageId = (int) $value; /** @var User $user */ $user = auth()->user(); /** @var null|WebhookMessage $message */ $message = self::find($messageId); if (null !== $message && $message->webhook->user_id === $user->id) { return $message; } } throw new NotFoundHttpException(); } public function webhook(): BelongsTo { return $this->belongsTo(Webhook::class); } public function webhookAttempts(): HasMany { return $this->hasMany(WebhookAttempt::class); } /** * Get the amount */ protected function sent(): Attribute { return Attribute::make( get: static fn ($value) => (bool) $value, ); } protected function webhookId(): Attribute { return Attribute::make( get: static fn ($value) => (int) $value, ); } }