inisiatif/model-shared
Kumpulan model Eloquent bersama untuk Inisiatif Zakat Indonesia: pekerjaan, tingkat pendidikan, wilayah (negara–provinsi–desa), dan status perkawinan. Mendukung relasi dinamis Branch dan Employee pada model Donor via resolveRelationUsing.
Donor, Degree, Region) and value objects (e.g., geographic hierarchies) that map directly to Inisiatif Zakat’s domain. Ideal for a Laravel monolith or microservices where core models are reused across modules (e.g., donor management, distribution workflows).Donor::resolveRelationUsing), reducing boilerplate for polymorphic associations. Risk: Tight coupling to Eloquent may complicate adoption in non-Laravel PHP projects.boot in service providers) for extending relations or adding custom logic. Example:
Donor::resolveRelationUsing('custom_tag', fn($model) => $model->morphTo());
Tradeoff: Extensions may diverge from the shared model’s intent over time.donors_table, degrees_table). Risk: Schema conflicts if your app already defines these tables.Donor::resolveRelationUsing) to link to your Branch/Employee models. Complexity: Low for simple relations; higher for complex polymorphic setups.ramsey/composer-install@4). Action Item: Verify compatibility with your Laravel version via composer why-not inisiatif/model-shared.| Risk Area | Severity | Mitigation |
|---|---|---|
| Indonesia-Specific Models | High | Customize geographic models for other regions or build wrappers. |
| Unmaintained Package | Medium | Fork the repo to patch issues (e.g., typos in PRs 28–30). |
| Dynamic Relation Overhead | Low | Document relation mappings in a RELATIONS.md file for future maintainers. |
| Migration Conflicts | High | Run php artisan schema:dump before integrating to identify clashes. |
| Laravel Version Drift | Medium | Pin dependencies in composer.json (e.g., "laravel/framework": "10.0"). |
| Zero Stars/Dependents | Low | Treat as a private internal package with guarded adoption. |
Region models?Donor) with custom fields? If so, what’s the strategy for keeping changes in sync with upstream?Donor::branch()) in CI? Mock the resolved classes or use a test database with stubbed models.Region models (country → village) could bloat queries. Are we using query scopes or caching (e.g., Region::where('province_id', ...)->with('districts'))?models service); not for standalone APIs.Assessment Phase (1–2 days):
donors table).composer create-project laravel/laravel sandbox
cd sandbox
composer require inisiatif/model-shared
php artisan migrate:status.Pilot Integration (3–5 days):
Donor::branch()).php artisan schema:dump --path=/tmp/baseline
composer require inisiatif/model-shared
php artisan schema:dump --path=/tmp/with-package
diff -u /tmp/baseline /tmp/with-package
Phased Rollout:
Donor, Degree, Region) with read-only access.Donor::employee()) and add custom fields.App\Models\Donor for Inisiatif\ModelShared\Models\Donor).| Component | Compatibility | Workaround |
|---|---|---|
| Laravel 10+ | ✅ Tested (releases post-2025) | Pin version in composer.json if needed. |
| PHP 8.1+ | ✅ Assumed | Use platform-check in CI to enforce. |
| MySQL/PostgreSQL | ✅ No DB-specific code | Test migrations on both. |
| Custom Donor Fields | ⚠️ Requires extension | Use Donor::extend() or trait injection. |
| Non-Eloquent ORMs | ❌ Incompatible | Rewrite relations manually or avoid. |
| Livewire/Inertia | ✅ Works if models are bound to views | Ensure dynamic relations are resolved before view rendering. |
composer.json extra to document relation mappings:
"extra": {
"model-shared": {
"relations": {
"Donor": {
"branch": "App\Models\Branch",
"employee": "App\Models\Employee"
}
}
}
}
publish:migrations).AppServiceProvider@boot.config/app.php to alias models (optional):
'aliases' => [
'Donor' => Inisiatif\ModelShared\Models\Donor::class,
],
class LegacyDonor extends Inisiatif\ModelShared\Models\Donor {
// Fallback methods for backward compatibility
}
CUSTOMIZATIONS.md file.How can I help you explore Laravel packages today?