- How do I install mathieutu/exporter in a Laravel application?
- Install it with composer require mathieutu/exporter. The package supports Laravel auto-discovery, so no manual service provider registration is expected. There are no migrations, queues, or other infrastructure steps described. After installation, add the Exportable trait to models and define their $export arrays.
- Which PHP and Laravel versions does mathieutu/exporter support?
- The overview does not state exact version constraints, so check the composer.json constraints and CI matrix in the repository before adopting it. Treat PHP and Laravel version drift as a real risk because the package appears to have a single maintainer and limited community validation. Run your test suite and a representative export on both the oldest and newest runtimes you plan to support.
- How do I export nested Eloquent relations with mathieutu/exporter?
- Define dot-notation keys in the model's $export array, such as user.profile.name, and the exporter traverses nested objects, relations, and collections to build the output array. Confirm the exact resolution behavior for your relation types with a focused test. Dot-notation traversal is convenient but can trigger lazy loading, so eager-load the relations you export.
- Can mathieutu/exporter export plain arrays and objects, not just Eloquent models?
- Yes. The package is described as exporting attributes from objects and arrays, with an Exportable trait plus an Exporter facade mapping a declarative attribute list to output arrays. It is still a Laravel-oriented package, so framework-agnostic PHP projects are a less natural fit. For non-Eloquent data, verify nested traversal and missing-key behavior with tests.
- Is mathieutu/exporter actively maintained and safe for production?
- The assessment treats it as effectively unmaintained until proven otherwise: it has 43 stars, a single maintainer, and a low composite score. The small surface area limits the risk because a Laravel engineer can vendor or fork it in days. It is most defensible for internal admin exports, CSV reporting, and prototypes, not for public versioned API contracts.
- What happens if an exported attribute or relation is missing in mathieutu/exporter?
- The assessment flags implicit null behavior for missing keys as a secondary risk, so do not assume failures are loud. Add contract tests that cover absent attributes, null relations, and empty collections. If you need exceptions or configurable fallbacks, wrap the exporter behind your own adapter and enforce that behavior there.
- Does mathieutu/exporter cause N+1 queries or lazy loading problems?
- Dot-notation traversal of relations can trigger lazy loading if the relations are not already loaded, which is the most likely production surprise. Eager-load the relations used in each export and review that in code review. Test exports with Model::preventLazyLoading() enabled and with strict mode to catch accidental queries.
- How does mathieutu/exporter compare with Laravel API Resources or Fractal?
- It trades type-safe Resource classes for terse per-model $export arrays, which is attractive when Resource boilerplate is disproportionate for internal tooling or rapid prototypes. API Resources and Fractal are better fits for public, versioned API contracts that need strict schema governance and reviewable contracts. Coexist with Resources rather than replacing them, and introduce the exporter behind a narrow interface.
- How should I test the output shape of a mathieutu/exporter export?
- Write contract tests that assert the exact output array for each export shape, including nested relations, collections, accessors, casts, and missing keys. Run a representative export against the oldest and newest PHP and Laravel versions you support. Keeping those tests at the adapter boundary makes it easier to swap implementations later without changing callers.
- How do I migrate away from or fork mathieutu/exporter later?
- Introduce it behind a narrow internal interface such as ExportPresenter::toArray($model, $attributes) so the package is an implementation detail. That preserves the option to replace it with API Resources, Fractal, or an internal fork with zero caller churn. If upstream stalls, vendor the small codebase or fork it and keep your contract tests as the safety net.