Download the PHP package wappo/laravel-schema-api without Composer
On this page you can find all versions of the php package wappo/laravel-schema-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wappo/laravel-schema-api
More information about wappo/laravel-schema-api
Files in wappo/laravel-schema-api
Package laravel-schema-api
Short Description This is a package that automatically exposes the DB schema in an api
License MIT
Homepage https://github.com/wappo/laravel-schema-api
Informations about the package laravel-schema-api
Laravel Schema API
Automatically expose your Laravel Eloquent models through a RESTful HTTP API with zero configuration. Perfect for building mobile apps, SPAs, or syncing data between systems.
What Does This Package Do?
Laravel Schema API automatically creates API endpoints for all your Eloquent models, giving you:
- Instant REST API: GET, PUT, DELETE operations on all your models without writing controllers
- Real-Time Broadcasting: WebSocket notifications when data changes (via Laravel Echo)
- Streaming JSON Responses: Memory-efficient NDJSON streaming for large datasets
- Incremental Sync: Built-in
?sinceparameter to fetch only changed/deleted records - Automatic Relationships: Stream related models with the
#[ApiInclude]attribute - Cascade Deletes: Automatically delete/restore related models when parents change
- Schema-Based Validation: Auto-generates validation rules from your database schema
- Type-Safe Client Generation: Generate TypeScript types and Vue forms from your models
Installation
Install the package via composer:
Publish the config file (optional):
That's it! Your models are now accessible via /schema-api/{table-name}.
Quick Start
Once installed, you can immediately access your models:
Example: Fetching Data
Response (NDJSON format - one JSON object per line):
Example: Incremental Sync
Fetch only records modified since a specific timestamp:
This returns both updated records and deleted IDs (if using soft deletes).
Example: Creating/Updating Records
Advanced Usage
Including Relationships
Stream related models alongside parent records using the #[ApiInclude] attribute:
Now when you fetch orders, you'll also get the rows and owner streamed as separate root-level entities:
Response:
Cascade Delete & Restore
Automatically delete or restore related models when the parent changes:
Safety Features:
- Models with
SoftDeletesare always safe to cascade delete - Models without
SoftDeletesrequireforceDelete: trueto prevent accidental data loss - When restoring a soft-deleted parent, only related records deleted at approximately the same time are restored (configurable tolerance)
Validation
Validation rules are automatically generated from your database schema:
Or provide custom validation rules:
Query Modifiers
Customize how models are queried using attributes:
Built-in modifiers:
LatestFirstModifier- Order bycreated_at DESCUpdatedFirstModifier- Order byupdated_at DESCSortQueryModifier- Custom sortingFilterQueryModifier- Filter by query parameters
Exclude Models from API
If you want to exclude a model from the HTTP API but still broadcast its changes via WebSockets:
Real-Time Broadcasting
Get instant notifications when data changes using Laravel's broadcasting system:
Two Broadcasting Modes:
-
syncmode (default) - Only broadcasts changes from the/schema-api/syncendpoint- Most predictable and transaction-safe
- Best for apps that exclusively use the sync endpoint
model-eventsmode - Broadcasts all Eloquent model changes- Captures changes from sync endpoint, console commands, direct Eloquent operations, etc.
- Respects
#[ApiIgnore]- won't broadcast excluded models (unlessshouldBroadcast: true) - Best for apps with multiple entry points for data changes
Client-Side Setup:
Configure Laravel Echo to listen for real-time updates:
Authorization:
By default, the package checks Laravel Gates to determine which users can view a model:
For custom authorization logic, bind your own implementation:
Important: Make sure you have Laravel Broadcasting configured with a driver like Pusher, Ably, or Redis.
Custom JSON Resources
Use your own JSON resource classes:
API Endpoints
List Models
Query Parameters:
?since=2025-01-01T00:00:00Z- Incremental sync (returns modified and deleted records)?gzip- Enable gzip compression
Response Format: NDJSON (newline-delimited JSON)
Get Single Model
Response Format: NDJSON with the model and any #[ApiInclude] relationships
List All Available Models
Returns metadata about all exposed models.
Batch Sync
Request Body: Array of operations
Response: NDJSON with the result of each operation
Configuration
Publish and edit config/schema-api.php:
Performance
The package is optimized for large datasets:
- Streaming Responses: Uses cursor pagination and NDJSON to handle millions of records without memory issues
- Efficient Relationship Loading: Batches parent records and uses
whereIn()to avoid N+1 queries - Optional Compression: Enable gzip compression with
?gzipparameter - No Model Hydration: Uses raw queries (
toBase()) for better performance
Example: Streaming 1 million records uses constant memory (~50MB) instead of loading everything into RAM.
Client Code Generation
Generate TypeScript types and Vue forms from your models:
This reads your model schemas and generates type-safe client code for your frontend.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Johan Östling
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-schema-api with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0