morphTo(); } public static function resolve(string $source, string $sourceType, string $externalId): ?Model { return static::query() ->where('source', $source) ->where('source_type', $sourceType) ->where('external_id', $externalId) ->first() ?->model; } public static function record(string $source, string $sourceType, string $externalId, Model $model): self { return static::query()->updateOrCreate( [ 'source' => $source, 'source_type' => $sourceType, 'external_id' => $externalId, ], [ 'model_type' => $model->getMorphClass(), 'model_id' => $model->getKey(), ], ); } }