Download the PHP package dilneiss/laravel-api-tool-kit without Composer
On this page you can find all versions of the php package dilneiss/laravel-api-tool-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dilneiss/laravel-api-tool-kit
More information about dilneiss/laravel-api-tool-kit
Files in dilneiss/laravel-api-tool-kit
Package laravel-api-tool-kit
Short Description set of tools to build an api with laravel
License MIT
Homepage https://github.com/ahmedesa/laravel-api-tool-kit
Informations about the package laravel-api-tool-kit
Laravel API tool kit
Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.
Contents
Installation
Api response
Dynamic Pagination
Filters
Api Generator
Actions
Media Helper
Enum
General tips
Installation
to publish config
use exception handler to standardize the error response Error Response
in App\Exceptions\Handler class extend the APIHandler class
use API Response Trait in Controller
App\Http\Controllers\Controller.php
:
check : API response
🔝 Back to contents
API Response
it is used to format your response to standard format and status codes for success responses, it will be
Success Response
Error Response
usage: you can use the trait inside the class you want to return the response form
and use it like this
Available Methods
🔝 Back to contents
Dynamic Pagination
use pagination dynamically
usage
to use dynamic pagination to get all users :
to get all users without pagination :
to get all users paginated 10 users per page:
by default pagination is 20 element per page you can change the default value from config/api-tool-kit
Filters
usage:
to create a filter class:
to set default filters to the Car model , in Car model you will add
to use it
if you want to override the default filters
options in Filter class
to create a custom query you will just create a new function in the class and add your query example filter by year:
filter by relationship :
🔝 Back to contents
API Generator
Usage :
when you type the command it will ask you whether you want default options :
- (N) it will ask you which files you want to generate .
- (Y) it will generate files for all options that exists in config/api-tool-kit
options :
in addition, the routes will be created and added in routes/api.php files
🔝 Back to contents
Actions
action is a laravel implementation of command design pattern which create a class where you can add your business logic in https://en.wikipedia.org/wiki/Command_pattern
usage:
The best practice to use the action class is to use dependency injection
you have many options 1-use laravel application container
2-inject it in the class in constructor
3-inject the class in laravel controller function
🔝 Back to contents
Media Helper
it is used to upload and delete files to storage
🔝 Back to contents
**Enum
bad practice : if I have two types of users (admin ,student) instead of hard coding the name of user type every time using it you can simply use the enum class
usage :
it will generate classes like this
methods:
🔝 Back to contents
General Tips
throw error instead of return json response
Bad:
good
🔝 Back to contents