Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Register all models in the morph map + lock it with a test

Paulo Castellano65116de8591b
diff --git a/CLAUDE.md b/CLAUDE.md
index ec414276c..0c066141f 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -297,6 +297,12 @@ Vue components must have a single root element.
- Example: `data_get($data, 'name')` instead of `$data['name']`.
- Use the third parameter for fallback values: `data_get($data, 'username', $sender->username)` instead of `$data['username'] ?? $sender->username`.
+## Eloquent Models & Morph Map
+
+- EVERY Eloquent model in `app/Models` MUST be registered in `Relation::enforceMorphMap([...])` inside `AppServiceProvider::configureMorphMap()`, keyed by a camelCase alias (e.g. `'postPlatform' => PostPlatform::class`).
+- When you add a new model, add it to the morph map in the same change. `tests/Unit/MorphMapTest.php` fails if any model is missing.
+- The alias is persisted in polymorphic columns, so never rename or remove an existing alias for a model that has stored rows.
+
## Imports
- NEVER use inline class references (e.g., `\DB::listen`, `\Str::uuid()`). ALWAYS import classes at the top of the file with a `use` statement.
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index b7b2cdf00..8d5ed7d9c 100644
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -8,6 +8,11 @@ use App\Listeners\StripeEventListener;
use App\Models\AccessToken;
use App\Models\Account;
use App\Models\AiUsageLog;
+use App\Models\Automation;
+use App\Models\AutomationNodeRun;
+use App\Models\AutomationNodeState;
+use App\Models\AutomationRun;
+use App\Models\AutomationTriggerItem;
use App\Models\Invite;
use App\Models\Media;
use App\Models\Notification;
@@ -114,6 +119,11 @@ class AppServiceProvider extends ServiceProvider
'accessToken' => AccessToken::class,
'account' => Account::class,
'aiUsageLog' => AiUsageLog::class,
+ 'automation' => Automation::class,
+ 'automationNodeRun' => AutomationNodeRun::class,
+ 'automationNodeState' => AutomationNodeState::class,
+ 'automationRun' => AutomationRun::class,
+ 'automationTriggerItem' => AutomationTriggerItem::class,
'invite' => Invite::class,
'media' => Media::class,
'notification' => Notification::class,
diff --git a/tests/Unit/MorphMapTest.php b/tests/Unit/MorphMapTest.php
new file mode 100644
index 000000000..859f53927
--- /dev/null
+++ b/tests/Unit/MorphMapTest.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\Relation;
+
+test('every Eloquent model is registered in the morph map', function () {
+ $mapped = array_values(Relation::morphMap());
+
+ $missing = collect(glob(app_path('Models/*.php')))
+ ->map(fn (string $file): string => 'App\\Models\\'.pathinfo($file, PATHINFO_FILENAME))
+ ->filter(fn (string $class): bool => class_exists($class)
+ && is_subclass_of($class, Model::class)
+ && ! (new ReflectionClass($class))->isAbstract())
+ ->reject(fn (string $class): bool => in_array($class, $mapped, true))
+ ->values()
+ ->all();
+
+ expect($missing)->toBe([]);
+});