PHPackages                             lexxsoft/odata - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lexxsoft/odata

ActiveLibrary

lexxsoft/odata
==============

Laravel OData request parser

1.3.0(7mo ago)468MITPHPPHP &gt;=8.1CI passing

Since Oct 26Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/lexxyar/odata)[ Packagist](https://packagist.org/packages/lexxsoft/odata)[ RSS](/packages/lexxsoft-odata/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (36)Used By (0)

Laravel OData REST
==================

[](#laravel-odata-rest)

[![Latest Stable Version](https://camo.githubusercontent.com/1c3e4557a9c9e47f0886f3f7a33c0303478db079dd77c52c05ddc02163534323/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f76)](https://camo.githubusercontent.com/1c3e4557a9c9e47f0886f3f7a33c0303478db079dd77c52c05ddc02163534323/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f76)[![GitHub](https://camo.githubusercontent.com/b6f8a4910fbad460e088c7602acc543a9ed94b0bbea55b080963e35f43b42622/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6578787961722f6f64617461)](https://camo.githubusercontent.com/b6f8a4910fbad460e088c7602acc543a9ed94b0bbea55b080963e35f43b42622/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6c6578787961722f6f64617461)[![Package validation status](https://github.com/lexxyar/odata/actions/workflows/validating.yml/badge.svg)](https://github.com/lexxyar/odata/actions/workflows/validating.yml/badge.svg)[![PHP Version Require](https://camo.githubusercontent.com/09c6b5f3a07d0438bf3e4b0ccda7174fdb23aff1ee99001f3be9ef3c546c64cb/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f726571756972652f706870)](https://camo.githubusercontent.com/09c6b5f3a07d0438bf3e4b0ccda7174fdb23aff1ee99001f3be9ef3c546c64cb/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f726571756972652f706870)[![License](https://camo.githubusercontent.com/fecf987dac85328afd7f32485fe7d0a9d3e30e9feac11ef164905679ee63b470/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f6c6963656e7365)](https://camo.githubusercontent.com/fecf987dac85328afd7f32485fe7d0a9d3e30e9feac11ef164905679ee63b470/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f6c6963656e7365)[![Total Downloads](https://camo.githubusercontent.com/f47f3f285fde4ded83e385eccddc78d1ca2e5b82bdd74de97fced8020c63625c/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f646f776e6c6f616473)](https://camo.githubusercontent.com/f47f3f285fde4ded83e385eccddc78d1ca2e5b82bdd74de97fced8020c63625c/687474703a2f2f706f7365722e707567782e6f72672f6c657878736f66742f6f646174612f646f776e6c6f616473)

Contents
========

[](#contents)

- [Installation](#installation)
    - [Requirements](#requirements)
    - [Setup](#setup)
    - [Update model requirements](#update-model-requirements)
- [OData features](#odata-features)
- [Data manipulations](#data-manipulations)
    - [Reading data](#reading-data)
    - [Updating data](#updating-data)
        - [Updating relations](#updating-relations)
        - [Updating relations with pivot](#updating-relations-with-pivot)
    - [Creating data](#creating-data)
    - [Deleting data](#deleting-data)
- [Using custom controller methods](#using-custom-controller-methods)
- [Data validation rules](#data-validation-rules)
- [Spatie laravel permissions](#spatie-laravel-permissions)

Installation
============

[](#installation)

Requirements
------------

[](#requirements)

ComponentVersionPHP8.1Laravel10.5Setup
-----

[](#setup)

```
composer require lexxsoft/odata
```

After installation all routes as `/odata/*` will be accessible

```
php artisan vendor:publish --provider="Lexxsoft\Odata\Providers\OdataServiceProvider"
```

After that `config/odata.php` file will appear.

Update model requirements
-------------------------

[](#update-model-requirements)

To make model as OData entity, you must use `Restable` trait.

```
use LexxSoft\odata\Traits\Restable;

class Log extends Model
{
    use HasFactory, Restable;
}
```

OData features
==============

[](#odata-features)

- Metadata
- CRUD
    - **C**reate
    - **R**ead
    - **U**pdate
    - **D**elete
- OData Entity
- OData request
    - Resource path
        - Simple request (i.e. `/odata/category`)
        - Count request (i.e. `/odata/category/$count`)
        - Request by key (i.e. `/odata/category(1)`)
        - Single field value request (i.e. `/odata/category(1)/name`)
        - Value request (i.e. `/odata/category(1)/name/$value`)
        - Nested entity request (i.e. `/odata/category(1)/products`)
        - Count nested entity (i.e. `/odata/category(1)/products/$count`)
        - Deep nested entity (i.e. `/odata/category(1)/products(2)/supplier/address/city/$value`)
    - System query options
        - `$orderby`
        - `$top`
        - `skip`
        - `$filter`
            - EQ
            - NE
            - GT
            - GE
            - LT
            - LE
            - AND
            - OR
            - NOT
            - substringof
            - endswith
            - startswith
        - `$expand`
            - Simple expand (i.e.`$expand=products`)
            - Deep expand (i.e. `$expand=products/supplier`)
            - Expand with count (i.e. `$expand=products($count=true)`)
        - `$select`
        - `$count=true` (ex. `$inlinecount`)
    - Custom query options (i.e. `/odata/products?x=y`)

Data manipulations
==================

[](#data-manipulations)

Reading data
------------

[](#reading-data)

To read data, use `GET` request. Also, you can add parameters to your query from `OData features` section

```
GET /odata/role?$top=5
```

Reading user with ID = 1

```
GET /odata/user(1)
```

Updating data
-------------

[](#updating-data)

To update data you should use `PUT` method. Then, fill request body by new data.

Request example:

```
PUT /odata/role(2)
```

```
{
  "name": "User role"
}
```

### Updating relations

[](#updating-relations)

To update Many-To-Many relationship, you need pass array of ID's for relation field name

```
{
  "id": 2,
  "permissions": [
    5,
    6,
    7
  ]
}
```

### Updating relations with pivot

[](#updating-relations-with-pivot)

Sometimes Many-To-Many table has additional fields. To update them, pass array of objects for relation field.

> Note, **key** field is required.

```
 {
  "id": 2,
  "permissions": [
    {
      "id": 5,
      "author": "Larry"
    },
    {
      "id": 8,
      "author": "John"
    }
  ]
}
```

Creating data
-------------

[](#creating-data)

To create new record, use `POST` request type

```
POST /odata/role
```

```
{
  "name": "New role"
}
```

Deleting data
-------------

[](#deleting-data)

To delete data, use `DELETE` request with record key

```
DELETE /odata/role(2)
```

Using custom controller methods
===============================

[](#using-custom-controller-methods)

OData plugin can make almost all CRUD operation automatically. But some cases should be operated individually. To make it real, OData plugin will search controller for model in path `/app/Http/Controllers` with filename pattern `Controller.php`. If controller file found, second step will be search corresponding method in class controller. Methods name are same as for resource controller. Use table below to check method name for yore case:

HTTP methodController class method nameGETindexPOSTstorePUTupdatePATCHupdateDELETEdestroyAs example, you have `User` model and `UserController` for it. But, when you make odata http request, you use plural name like `/odata/users`. Be carefully with this part.

Data validation rules
=====================

[](#data-validation-rules)

Operations like `create` or `update` should validate data, which comes from client. for this purpose `ValidationRulesGenerator` class is used. It generate validation rules **only** for `Restable` model, using database fields description. And, by default, it generate rules only for `fillable` fields.

Spatie laravel permissions
==========================

[](#spatie-laravel-permissions)

If you use [laravel-permission](https://spatie.be/docs/laravel-permission/v5/introduction) from Spatie, then `Role`model and `Permission` model not use `Restable` trait by default. To make them RESTable, you should create yore own models (for example, via `php artisam make:model` command) and extends yore new models from `\Spatie\Permission\Models\*` models

```
/** Extended Role model */
namespace App\Models;

use Lexxsoft\Odata\Primitives\Restable;

class Role extends \Spatie\Permission\Models\Role
{
  use Restable;
}
```

```
/** Extended Permission model */
namespace App\Models;

use Lexxsoft\Odata\Traits\Restable;

class Permission extends \Spatie\Permission\Models\Permission
{
    use Restable;
}
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance65

Regular maintenance activity

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~181 days

Total

35

Last Release

214d ago

Major Versions

0.11.4 → 1.0.02023-10-01

PHP version history (2 changes)0.7.0PHP ^7.3|^8.0

1.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/70fbcc6596ad0ba415f4d63f13fb0a0adb1242a85e3032cc6a2a8db322f12982?d=identicon)[lexxyar](/maintainers/lexxyar)

---

Top Contributors

[![lexxyar](https://avatars.githubusercontent.com/u/23395412?v=4)](https://github.com/lexxyar "lexxyar (114 commits)")

---

Tags

laravellibraryodatauniversal platform

### Embed Badge

![Health badge](/badges/lexxsoft-odata/health.svg)

```
[![Health](https://phpackages.com/badges/lexxsoft-odata/health.svg)](https://phpackages.com/packages/lexxsoft-odata)
```

###  Alternatives

[panphp/pan

A simple, lightweight, and privacy-focused product analytics php package.

1.2k94.6k5](/packages/panphp-pan)[mookofe/tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

5552.5k](/packages/mookofe-tail)[nikolag/laravel-square

Square API integration with Laravel built on nikolag/core

3827.3k](/packages/nikolag-laravel-square)[mariojgt/witchcraft

A Laravel Package Witchcraft, a quick start for new laravel Packages

312.6k](/packages/mariojgt-witchcraft)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
