Download the PHP package lexxsoft/odata without Composer
On this page you can find all versions of the php package lexxsoft/odata. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lexxsoft/odata
More information about lexxsoft/odata
Files in lexxsoft/odata
Informations about the package odata
Laravel OData REST
Contents
- Installation
- Requirements
- Setup
- Update model requirements
- OData features
- Data manipulations
- Reading data
- Updating data
- Updating relations
- Updating relations with pivot
- Creating data
- Deleting data
- Using custom controller methods
- Data validation rules
- Spatie laravel permissions
Installation
Requirements
Component | Version |
---|---|
PHP | 8.1 |
Laravel | 10.5 |
Setup
After installation all routes as /odata/*
will be accessible
After that config/odata.php
file will appear.
Update model requirements
To make model as OData entity, you must use Restable
trait.
OData features
- [x] Metadata
- [x] CRUD
- [x] Create
- [x] Read
- [x] Update
- [x] Delete
- [x] OData Entity
- [ ] OData request
- [ ] Resource path
- [x] Simple request (i.e.
/odata/category
) - [x] Count request (i.e.
/odata/category/$count
) - [x] Request by key (i.e.
/odata/category(1)
) - [X] Single field value request (i.e.
/odata/category(1)/name
) - [X] 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
)
- [x] Simple request (i.e.
- [ ] System query options
- [x]
$orderby
- [x]
$top
- [x]
skip
- [ ]
$filter
- [x] EQ
- [x] NE
- [x] GT
- [x] GE
- [x] LT
- [x] LE
- [ ] AND
- [ ] OR
- [ ] NOT
- [X] substringof
- [X] endswith
- [X] startswith
- [X]
$expand
- [x] Simple expand (i.e.
$expand=products
) - [x] Deep expand (i.e.
$expand=products/supplier
) - [X] Expand with count (i.e.
$expand=products($count=true)
)
- [x] Simple expand (i.e.
- [X]
$select
- [X]
$count=true
(ex.$inlinecount
)
- [x]
- [X] Custom query options (i.e.
/odata/products?x=y
)
- [ ] Resource path
Data manipulations
Reading data
To read data, use GET
request. Also, you can add parameters to your query from OData features
section
Reading user with ID = 1
Updating data
To update data you should use PUT
method. Then, fill request body by new data.
Request example:
Updating relations
To update Many-To-Many relationship, you need pass array of ID's for relation field name
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.
Creating data
To create new record, use POST
request type
Deleting data
To delete data, use DELETE
request with record key
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 <Singular entity name>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 method | Controller class method name |
---|---|
GET | index |
POST | store |
PUT | update |
PATCH | update |
DELETE | destroy |
As 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
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
If you use laravel-permission 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
All versions of odata with dependencies
ext-dom Version *