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

Api Model Laravel Package

outrightvision/api-model

View on GitHub
Deep Wiki
Context7

Generate Laravel-like Api Models

Frequently asked questions about Api Model
How do I install outrightvision/api-model in a Laravel project?
Run `composer require outrightvision/api-model` in your project directory. The package follows Laravel’s conventions, so no additional configuration is needed for basic usage. Ensure your Laravel version (10/11) is compatible—check the package’s documentation for exact requirements. If using a custom namespace, update the service provider binding in `config/app.php`.
Does this package work with Laravel Sanctum or Passport for authentication?
Yes, the package integrates seamlessly with Laravel’s auth systems like Sanctum or Passport. It generates API models that respect middleware and guards, so you can apply auth logic (e.g., `@auth:api`) directly to routes or models. Test with your existing auth setup to ensure token validation and role-based access work as expected.
Can I use this for GraphQL APIs alongside Laravel Lighthouse?
The package is designed for RESTful APIs first, but it can generate GraphQL-like models if your API uses a hybrid approach. For full GraphQL support, you may need to manually extend the generated models or use it alongside Lighthouse for schema definition. Avoid mixing if your project relies heavily on Lighthouse’s schema-first workflow.
What Laravel versions does outrightvision/api-model support?
The package is optimized for Laravel 10 and 11, with potential backward compatibility for Laravel 9. Verify the latest release notes for exact version support, as breaking changes in Laravel’s core (e.g., Eloquent updates) could affect integration. Always test in a staging environment before upgrading.
How does this handle complex API relationships (e.g., polymorphic, many-to-many)?
The package abstracts relationship handling to match Eloquent’s conventions, so polymorphic and many-to-many relationships are supported out of the box. For nested serialization, use Laravel’s built-in `with()` or `load()` methods, or extend the model’s `$appends` or `$hidden` properties. Custom logic may require overriding the generated API responses.
Will this work with non-MySQL databases like PostgreSQL or SQLite?
Yes, the package leverages Laravel’s database agnosticism, so it supports PostgreSQL, SQLite, and other databases via Eloquent. Ensure your database connection is properly configured in `config/database.php` and that the schema matches the generated models. Test with complex data types (e.g., JSON columns) to confirm compatibility.
Can I incrementally adopt this package without rewriting existing API controllers?
Yes, the package is designed for gradual adoption. Start by generating models for new endpoints, then migrate existing controllers to use the generated models. Use feature flags or middleware to toggle between old and new API layers during transition. Avoid mixing hand-written and generated logic in the same controller.
How does performance compare to manually written API resources?
The package introduces minimal overhead for model generation, but dynamic serialization and validation may add slight latency compared to hand-optimized resources. Benchmark with tools like Laravel Debugbar or k6 to compare response times. For high-throughput APIs, consider caching generated models or pre-compiling responses.
Are there built-in tools for testing API contracts or mocking responses?
The package doesn’t include dedicated testing tools, but you can use Laravel’s built-in testing helpers (e.g., `Http::fake()`, `JsonResponse::assertExactJson`) to mock API responses. For contract testing, pair it with tools like Pest or PHPUnit to validate request/response schemas. Custom factories can generate test data matching the API models.
What alternatives exist for Laravel API scaffolding, and when should I choose this package?
Alternatives include Laravel API Resources, Forest Admin, or custom packages like Spatie’s Laravel API. Choose this package if you need rapid scaffolding with Eloquent-like syntax and want to avoid manual contract definition. Opt for Forest Admin if you prioritize admin panels, or API Resources if you need fine-grained control over serialization. Evaluate based on your project’s complexity and team familiarity with Laravel.
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours