Skip to content

Clarify storeWebhook with static:: and cover custom webhook_model (refs #253)#254

Closed
freekmurze wants to merge 1 commit into
mainfrom
fix-storewebhook-late-static-binding
Closed

Clarify storeWebhook with static:: and cover custom webhook_model (refs #253)#254
freekmurze wants to merge 1 commit into
mainfrom
fix-storewebhook-late-static-binding

Conversation

@freekmurze

Copy link
Copy Markdown
Member

Background

Issue #253 reports that WebhookCall::storeWebhook() uses self::create(...) and therefore "ignores the configured webhook_model class context," storing/validating against the wrong connection/table.

After investigation, the reported bug does not actually reproduce. WebhookProcessor calls $this->config->webhookModel::storeWebhook(...), and inside that method self::create(...) is a forwarding static call. PHP preserves the late-static-binding scope across forwarding calls, and Eloquent's Model::__callStatic() does return (new static)->$method(...). So static resolves to the configured custom model and the row is created against that model's table/connection.

A standalone proof:

class Base {
    public static function __callStatic($m, $a) { return static::class; }
    public static function make() { return self::create(); }       // forwarding
    public static function makeHard() { return Base::create(); }    // non-forwarding
}
class Custom extends Base {}

Custom::make();      // 'Custom'  <-- self:: still resolves correctly
Custom::makeHard();  // 'Base'    <-- only a hardcoded class name breaks

There are no hardcoded WebhookCall:: references in src/, so nothing in the package actually exhibits the reported problem.

Changes

  • Switch the self:: calls in storeWebhook() (and its static helpers) to static::. This is a no-op behaviorally, but makes the intent explicit and matches the existing static::where(...) in prunable().
  • Add a regression test that stores a webhook through a custom webhook_model mapped to its own table (custom_webhook_calls) and asserts the row lands in that table and the returned instance is the custom model.

Testing

All 29 tests pass locally (vendor/bin/pest).

storeWebhook() already respects a configured custom webhook_model: the
self::create() call is a forwarding static call, so Eloquent's
__callStatic (which uses new static) resolves to the configured model and
its table/connection. Switch to static:: to make that intent explicit and
add a regression test storing through a custom model on its own table.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@freekmurze

Copy link
Copy Markdown
Member Author

Closing: based on a stale local checkout that diverged from current main, so this is conflicting. I'll recreate the regression test on a fresh branch off current main. The analysis on #253 (not a bug, due to PHP forwarding-call semantics) still stands.

@freekmurze freekmurze closed this Jun 3, 2026
@freekmurze freekmurze deleted the fix-storewebhook-late-static-binding branch June 3, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant