Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Cti

Laravel Cti Laravel Package

pannella/laravel-cti

View on GitHub
Deep Wiki
Context7

An extension to Laravel's ORM adding support for class table inheritance

Frequently asked questions about Laravel Cti
How does Laravel CTI differ from Laravel's built-in Single Table Inheritance (STI)?
Laravel CTI uses separate tables for parent and subtype models, unlike STI which stuffs all columns into one table. This avoids nullable columns for every subtype and enforces database-level foreign key constraints. CTI also supports complex queries on subtype-specific columns without bloating the parent schema.
Can I migrate an existing Laravel app using STI or polymorphic relations to CTI?
Yes, but it requires careful planning. You’ll need to restructure your database schema to split shared and subtype-specific columns, update models to use `HasSubtypes`, and handle data mapping during migration. The package provides no built-in migration tool, so custom logic may be needed for legacy data.
Will CTI work with Laravel Scout for search functionality?
Absolutely. Subtype models can be searchable with Scout, but you’ll need to configure custom analyzers or indexes to handle the joined structure. The package doesn’t integrate directly with Scout, but you can query subtypes like any other Eloquent model and pass them to Scout’s searchable trait.
How do I handle cases where a parent record lacks a subtype (orphaned records)?
The package lets you configure this behavior via the `$orphanedRecordBehavior` property on the parent model. Options include returning just the parent model, throwing an exception, or using a fallback subtype. Default behavior is to return the parent model without subtype data.
Does Laravel CTI support Laravel Nova or Livewire for subtype-specific forms?
Yes, but you’ll need to build subtype-specific panels or forms manually. The package resolves model types automatically, so you can dynamically render fields based on the resolved subtype. For Nova, use custom fields or tool panels; for Livewire, leverage the resolved model type in your component logic.
Are there performance concerns with CTI’s automatic joins for subtype queries?
CTI automates joins for subtype queries, which can introduce overhead for complex queries. Benchmark your high-traffic endpoints, especially those filtering on subtype-specific columns. Consider denormalizing frequently accessed subtype data or using query caching for performance-critical paths.
How do I add a new subtype to an existing CTI hierarchy without breaking the parent schema?
Adding a new subtype only requires creating a new subtype table with a foreign key to the parent and updating the `$subtypeMap` in the parent model. The package handles the rest, including type resolution and persistence. No changes to the parent schema are needed, making it future-proof for extensible domains.
Does Laravel CTI support Laravel API Resources for automatic subtype casting in responses?
Yes, the package automatically resolves and casts subtypes in API responses. When you return an `AssessmentResource`, it will dynamically return the correct subtype (e.g., `QuizResource` or `SurveyResource`) based on the database record. No extra configuration is required beyond defining your resources.
What Laravel and PHP versions does this package support?
Laravel CTI supports Laravel 8 through 13 and requires PHP 8.1 or higher. It leverages Eloquent features like attributes (e.g., `#[Subtype]` annotations in newer Laravel versions), so ensure your project meets these requirements. No breaking changes are planned for supported versions.
How do I test CTI models with Pest or PHPUnit?
The package includes built-in tests for core functionality, but you’ll need custom assertions for subtype-specific logic. Test type resolution, saving/updating across tables, and edge cases like orphaned records. Use Eloquent’s testing helpers (e.g., `assertModelMissing`) and mock subtype tables for isolated tests.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
aashan/pimcore-mcp-bundle
solution-forest/ai-kit-core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin