PHP Classes

Laravel REST API: Create an API using Laravel Eloquent models

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 72 All time: 10,250 This week: 59Up
Version License PHP version Categories
lara_rest 1.0.0GNU General Publi...5HTTP, PHP 5, Libraries, Web services
Description 

Author

This package can create REST API applications using Laravel Eloquent models.

It can perform several steps to configure API handler classes to call model classes to generate the values used to respond to REST API requests.

Currently, it can:

- Register a service provider class

- Mapping API request parameters to model classes that will handle the access to model objects

- Perform operations to customize the REST API requests

- Configure the mapping of request URL parameters to API request routes.

Innovation Award
PHP Programming Innovation award nominee
February 2022
Number 4
Many Web applications provide APIs to expose their functionalities to external applications.

Usually, those applications provide a REST API to manipulate information records stored in databases accessed using model classes.

This package makes it simpler to create complex REST API by reducing the effort to write code to set up and configure REST APIs that provide access to many model classes in the same API provided by applications written with the Laravel framework.

Manuel Lemos
Picture of Raskin Veniamin
  Performance   Level  
Innovation award
Innovation award
Nominee: 6x

Winner: 1x

 

Documentation

Lp api rest

This package allows you to create a simple REST API on the basis of standard models (Eloquent) of the Larave 5.x Framework.

install

  • composer require venya/lp-rest

Configure

  • Add app.php

    $app->register(LpRest\RestServiceProvider::class);

    //$app->register(LpRest\RestServiceProviderLumen::class); //for Lumen

  • Add in AppServiceProvider::register

    //Set model aliases app()->afterResolving(CommonRepositoryModelProvider::class, function(CommonRepositoryModelProvider $mp) { $mp->addModelAliases('user', \App\User::class); });

    //Change access provider $this->app->bind(CommonRepositoryAccessProvider::class, ApiAccessProvider::class );

    //Change response schema $this->app->bind(CommonResponse::class, ApiCustomResponse::class );

    //Custom routes and etc $this->app->afterResolving(RestServiceHelper::class, function(RestServiceHelper $sp) { $sp->setRouteGroupOptions([ 'prefix' => 'api/rest', //'middleware' => 'auth', ]); });

API

  • GET /api/rest/:modelName[/:relations] - get all items
  • GET /api/rest/:modelName/:id[/:relations] - get one item
  • POST /api/rest/:modelName {:json body} - create item
  • PUT /api/rest/:modelName/:id {:json body} - update item
  • DELETE /api/rest/:modelName/:id - remove item
  • POST /api/rest/:modelName/:id {:json body - arguments} - Call model method
  • POST /api/rest/multi {:json body - config any query} - Causes several methods at a time

TODO FILTER DESCRIPTION

  • /api/rest/file?filter[]=created_at:range:2018-03-01,2018-05-20&filter[]=tags.id:1&filter[]=id:in:1,2,3,18

  Files folder image Files (26)  
File Role Description
Files folder imagesrc (3 files, 6 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:72
This week:0
All time:10,250
This week:59Up