nanigans/single-table-inheritance
User, AdminUser, SuperAdminUser).SoftDeletes, Validating) without subclassing conflicts.type or model_kind instead of Laravel’s default morph_map).WHERE type = 'AdminUser' filters) compared to class-table inheritance (CTI) or foreign-key associations for deep hierarchies.MorphTo/MorphMany), which may require additional logic if the package is used alongside Laravel’s native polymorphism.create_function).type) to store model class names. Migration must be backward-compatible if the column already exists.NULL columns for unused inherited fields. May require partial indexing or denormalization for large datasets.WHERE type IN (...) AND ...).type column to a live table) requires downtime or careful backfilling.Vehicle → Car → ElectricCar), or could foreign-key associations or polymorphic relations suffice?type column interact with existing indexes/constraints?instanceof, serialization)?array_merge_recursive vs. spread operator).Post/Comment morphing to User).User → AdminUser) to validate performance and query patterns.type column (or custom name) to the target table:
Schema::table('users', function (Blueprint $table) {
$table->string('type')->nullable()->after('id');
});
type values (e.g., User::all()->each(fn ($u) => $u->forceFill('type', 'User')->save())).use Nanigans\SingleTableInheritance\SingleTableInheritance;
class User extends Model {
use SingleTableInheritance;
}
class AdminUser extends User {
// Inherits STI automatically
}
type (e.g., User::where('type', 'AdminUser')).instanceof, serialization, and trait conflicts.saved()/deleted() hooks (STI models trigger events for the parent class).toArray()/toJson() handle type correctly (may need custom casting).type.type column to production tables (with downtime if needed).type column if needed).Validating trait) reduces duplication.AdminUser vs. User).type.WHERE type IN (...) queries.type or fail to reconstruct models.instanceof checks may behave unexpectedly (e.g., AdminUser instanceof User returns true).How can I help you explore Laravel packages today?