Laravel Design Pattern Generator (api generator)
you can create your restful api easily by using this library
and you can filter, sort and include eloquent relations based on a request
Installation:
Require this package with composer using the following command:
$ composer require g4t/laravel-design-pattern
$ php artisan vendor:publish --provider=g4t\Pattern\PatternServiceProvider
Usage
config
You will find jsonapi.php
in folder relations
, sortable
columns and filterable
columns
This is where you will write Commands:
full command
$ php artisan make:repo User --c --r --m
or if you have model
$ php artisan make:repo User --c --r --model=User
--force
command
and you can use Available command options:
Command | Description |
---|---|
--c |
Create Controller and linked with repository |
--m |
Create Model and linked with Controller Functions |
--model={ModelName} |
Insert model in controller if you have model |
--r |
Create apiResource Route in api.php |
--force |
override existing Repository |
Parameters to controlling data:
You can modify parameters in config/jsonapi.php
FILTER A QUERY BASED ON A REQUEST
/users?filter[name]=John
INCLUDING RELATIONS BASED ON A REQUEST
/users?include=posts
/users?include=posts,comments
SORTING A QUERY BASED ON A REQUEST
/users?sort=id
/users?sort=-id
TAKE DATA
/users?take=10
SKIP DATA
/users?skip=10
CUSTOM CONDITIONS
/users?where={"column":"parent_to","condition":"!=", "value":"0"}
License
Laravel Design Pattern Generator is free software licensed under the MIT license.