. */ declare(strict_types=1); namespace FireflyIII\Models; use Eloquent; use FireflyIII\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Carbon; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * FireflyIII\Models\WebhookMessage * * @property int $id * @property Carbon|null $created_at * @property Carbon|null $updated_at * @property string|null $deleted_at * @property int $webhook_id * @property bool $sent * @property bool $errored * @property int $attempts * @property string $uuid * @property array $message * @property array|null $logs * @property-read Webhook $webhook * @method static Builder|WebhookMessage newModelQuery() * @method static Builder|WebhookMessage newQuery() * @method static Builder|WebhookMessage query() * @method static Builder|WebhookMessage whereAttempts($value) * @method static Builder|WebhookMessage whereCreatedAt($value) * @method static Builder|WebhookMessage whereDeletedAt($value) * @method static Builder|WebhookMessage whereErrored($value) * @method static Builder|WebhookMessage whereId($value) * @method static Builder|WebhookMessage whereLogs($value) * @method static Builder|WebhookMessage whereMessage($value) * @method static Builder|WebhookMessage whereSent($value) * @method static Builder|WebhookMessage whereUpdatedAt($value) * @method static Builder|WebhookMessage whereUuid($value) * @method static Builder|WebhookMessage whereWebhookId($value) * @mixin Eloquent * @property-read Collection|WebhookAttempt[] $webhookAttempts * @property-read int|null $webhook_attempts_count */ class WebhookMessage extends Model { 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). * * @param string $value * * @return WebhookMessage * @throws NotFoundHttpException */ public static function routeBinder(string $value): WebhookMessage { if (auth()->check()) { $messageId = (int) $value; /** @var User $user */ $user = auth()->user(); /** @var WebhookMessage $message */ $message = self::find($messageId); if (null !== $message && $message->webhook->user_id === $user->id) { return $message; } } throw new NotFoundHttpException; } /** * @codeCoverageIgnore * @return BelongsTo */ public function webhook(): BelongsTo { return $this->belongsTo(Webhook::class); } /** * @codeCoverageIgnore * @return HasMany */ public function webhookAttempts(): HasMany { return $this->hasMany(WebhookAttempt::class); } }