laracraft-tech/laravel-dynamic-model
DatabaseMigrations and RefreshDatabase traits for CI.fillable fields). Mitigate with schema validation (e.g., Schema::hasTable() checks).DB::connection() explicitly where needed.Schema::create() with runtime table names.searchableAs configured dynamically).Resource classes, but ensure toArray() handles missing columns gracefully.| Phase | Action | Tools/Strategies |
|---|---|---|
| Assessment | Audit existing models for multi-table patterns. | Static analysis (PHPStan), code reviews. |
| POC | Implement 1–2 dynamic models in a non-critical module. | Feature flags, A/B testing. |
| Incremental Rollout | Replace read-heavy traditional models first (e.g., reports). | Database views as fallback. |
| Full Adoption | Migrate write-heavy models last (e.g., user profiles). | Transaction rollback testing. |
| Deprecation | Phase out traditional models via deprecated trait warnings. | Laravel’s Deprecates facade. |
order) may need quoting.hasMany/belongsTo.pdo, pdo_mysql/pdo_pgsql (standard in Laravel).composer require laracraft-tech/laravel-dynamic-model
Publish config (if any) and update config/database.php for multi-DB support.use LaracraftTech\DynamicModel\DynamicModel;
class MultiTableModel extends DynamicModel
{
protected $table = null; // Resolved at runtime
protected $connection = 'dynamic_db';
}
getTable() or use a service provider to inject table names.public function getTable()
{
return 'tenant_' . $this->tenant_id . '_' . $this->resource_type;
}
ModelNotFoundException.Schema::hasColumn() checks.Illuminate\Database\Events\QueryExecuted).$table resolutions).getTable() logic and DB connections.debug() method to dump resolved table/connection.DB::enableQueryLog() for dynamic queries.tenant_id + resource_type).getTable() logic for edge cases.How can I help you explore Laravel packages today?