Download the PHP package hellomohsinhello/laravel-relation-parser without Composer
On this page you can find all versions of the php package hellomohsinhello/laravel-relation-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hellomohsinhello/laravel-relation-parser
More information about hellomohsinhello/laravel-relation-parser
Files in hellomohsinhello/laravel-relation-parser
Package laravel-relation-parser
Short Description Easily load model relations from frontend without changing your API
License MIT
Informations about the package laravel-relation-parser
Installation
Version | Laravel | PHP |
---|---|---|
1.x | 10, 11 | >= 8.1 |
0.3.x | 8, 9, 10 | >= 7.3 |
Usage
Allow your application to load any model relation in the response without the need of changing your API controllers.
Pass a comma separated relations to your http request.
Loading relations
Add a with
param to your HTTP request
/users?with=orders,posts,anyOtherRelation
Loading relation counts
Add a with_count
param to your HTTP request
/users?with_count=orders,anyOtherRelation,anotherRelationToCount,blaBlaBla
Loading relations and counts
/users?with=orders&with_count=orders
In your controller
Response example
Customize
If with
or with_count
params are used for something else in your application then you can customize those params
in loadRelations()
method.
$this->loadRelations($users, $request, 'customWithParam', 'custom_with_count_param');
Testing
All versions of laravel-relation-parser with dependencies
illuminate/http Version ^10.0 || ^11.0
illuminate/database Version ^10.0 || ^11.0