![](/assets/lara-api-rest.jpeg)
The simplest way to create REST API with Laravel
Simple yet powerful |
Easy to use and learn |
Fully featured REST API for your Eloquent models and relationships with the simplicity of Laravel as you love it. |
Utilizes standard Laravel features such as Request classes, Policies and API Resources. |
Introduction
Laravel Api Controller uses the most powerful features of Laravel: Eloquent models and relationships, policies, request classes, and API resources, which makes it incredibly powerful and extensible, yet simple to get started with.
This package automates many of your CRUD actions for API's in Laravel.
Its as quick as running php artisan make:api {MODEL}
which dependant on your options will create the following:
-
Eloquent Model
-
Api Controller
-
Policy File
-
Request File
-
Response Resource File
-
API Route entry
you will now have an working api that you can customise as needed.
Features
- REST API for models and relationships with advanced yet simple dynamic filtering on the list method, : eg:
/api/your_model?filter[field]=x&filter[another!]=y&limit=5
- Scope aware and can include scopes on the filters: eg:
/api/your_model?myScope=x
- Uses Laravel Gates so most permission addon packages work (tested with pure Laravel Gates & Spatie permissions package)
- Comprehensive set of endpoint hooks
- Events on API endpoints
- Can deal with relationships - hasOne, hasMany, BelongsToOne, BelongsToMany for retrieving and saving
- Automatic mapping from camel to snake / snake to camel based on your settings -- no more having to use mappers in your frontend code / backend code
- Pagination
- Straightforward authorization and validation
- Response field protection / mapping / transformation via Api Resources
- artisan command to generate full api per eloquent model
- actively maintained and developed as in production environment on all our Laravel Projects
Usage
Generate a new Api Controller, Repository and Route via php artisan make:api {ModelName}
This will create an Api/ModelNameController
for you and you will have the basic routes in place as follows:
- GET api/v1/{model_name} - list all/paged/filtered (class::index)
- GET api/v1/{model_name}/$id - Show a specified id (class::show)
- POST api/v1/{model_name} - Insert a new record (class::store)
- PUT api/v1/{model_name}/$id - Update an existing record (class::update)
- DELETE api/v1/{model_name}/$id - Delete an existing record (class::destroy)