Download the PHP package novabytes/laravel-odata without Composer
On this page you can find all versions of the php package novabytes/laravel-odata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-odata
Laravel OData
OData 4 for Laravel. Query (filter, select, expand, sort, paginate) and CRUD (create, read, update, delete) your Eloquent models via OData-compliant endpoints.
Built on top of novabytes-labs/odata-query-parser.
Table of Contents
- Installation
- Quick Start
- CRUD Endpoints
- Query Options
- PascalCase Conversion
- Security
- Entity Sets & Metadata
- Metadata Endpoints
- Configuration
- Advanced Usage
- Requirements
- License
Installation
Publish the config file:
Quick Start
Your API now accepts OData queries:
CRUD Endpoints
Enable auto-registered CRUD routes for your entity sets:
This registers the following routes:
| Method | Route | Description |
|---|---|---|
GET |
/api/Products |
List with OData query options |
POST |
/api/Products |
Create entity |
GET |
/api/Products/{key} |
Get single entity |
PUT |
/api/Products/{key} |
Full replace |
PATCH |
/api/Products/{key} |
Partial update |
DELETE |
/api/Products/{key} |
Delete entity |
Request bodies accept both PascalCase and snake_case field names. Only fields listed in allowedCreates/allowedUpdates are accepted — others return 400.
The CSDL and OpenAPI metadata endpoints automatically reflect CRUD capabilities.
Query Options
| Option | Example | Description |
|---|---|---|
$filter |
Price gt 100, contains(Name,'Widget'), Reviews/any(r:r/Rating gt 4) |
Filter results using comparison operators, functions, and lambda expressions |
$select |
Name,Price |
Choose which properties to return (primary key always included) |
$expand |
Category, Reviews($filter=Rating gt 4;$top=5) |
Eager-load relationships with optional nested query options |
$orderby |
Price desc, Name asc,Price desc |
Sort results by one or more properties |
$top |
10 |
Limit the number of results |
$skip |
20 |
Skip a number of results (for pagination) |
$count |
true |
Include total count in the response |
All OData 4 comparison operators (eq, ne, gt, ge, lt, le), logical operators (and, or, not), and 30+ built-in functions are supported. See the parser README for the full list.
PascalCase Conversion
OData uses PascalCase property names. This package automatically converts them to Eloquent's snake_case:
| OData | Eloquent |
|---|---|
Price |
price |
CategoryId |
category_id |
IsActive |
is_active |
Category (expand) |
category (relationship) |
Define your allowlists in snake_case — the conversion is handled for you.
Security
Every filterable, sortable, expandable, and selectable field must be explicitly whitelisted. Any request for a non-whitelisted field throws a 400 Bad Request by default.
If no allowlist is set for a given operation, that operation is unrestricted.
Entity Sets & Metadata
Register your models and their allowlists centrally in config/odata.php to enable:
- Auto-generated
$metadata(CSDL XML) endpoint for OData clients - Auto-generated OpenAPI 3.0 spec for human-readable documentation
- Shared allowlists — no need to repeat
allowedFilters()etc. in every controller
When entity_sets are configured, controllers can omit explicit allowlists:
Metadata Endpoints
When metadata.enabled is true, two routes are registered automatically:
| Endpoint | Content-Type | Description |
|---|---|---|
GET {prefix}/$metadata |
application/xml |
OData v4 CSDL document — used by Power BI, Excel, and OData client libraries |
GET {prefix}/openapi.json |
application/json |
OpenAPI 3.0 spec — use with Swagger UI, Redoc, or any API docs tool |
Both are auto-generated from your Eloquent models and the entity_sets config. Zero annotations needed — columns, types, and nullability are discovered from the database schema; relationships are discovered via reflection.
Configuration
Advanced Usage
Using toBuilder()
Existing query as starting point
Requirements
- PHP >= 8.2
- Laravel 11, 12, or 13
License
MIT
All versions of laravel-odata with dependencies
novabytes/odata-query-parser Version ^0.3.0 || ^0.2.0 || ^0.1.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/support Version ^11.0|^12.0|^13.0