PHP Classes

Laravel REST API: Create an API using Laravel Eloquent models

Recommend this page to a friend!
  Info   View files Documentation   View files View files (26)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 72 All time: 10,232 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  
Name: Raskin Veniamin <contact>
Classes: 12 packages by
Country: Russian Federation Russian Federation
Age: ???
All time rank: 2207 in Russian Federation Russian Federation
Week rank: 234 Down14 in Russian Federation Russian Federation Down
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  
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

  Files folder image Files  /  src  
File Role Description
Files folder imageCommands (1 file)
Files folder imageControllers (3 files)
Files folder imageFacades (1 file)
Files folder imagemigrations (1 file)
Files folder imageModels (2 files)
Files folder imageRepositories (12 files)
  Plain text file RestServiceHelper.php Class Class source
  Plain text file RestServiceProviderLaravel.php Class Class source
  Plain text file RestServiceProviderLumen.php Class Class source

  Files folder image Files  /  src  /  Commands  
File Role Description
  Plain text file AccessFillCommand.php Class Class source

  Files folder image Files  /  src  /  Controllers  
File Role Description
  Plain text file CommonController.php Class Class source
  Plain text file CommonResponse.php Class Class source
  Plain text file CommonResponseBase.php Class Class source

  Files folder image Files  /  src  /  Facades  
File Role Description
  Plain text file CommonRepositoryAccessProvider.php Class Class source

  Files folder image Files  /  src  /  migrations  
File Role Description
  Plain text file 2018_03_12_092835_perm_group.php Class Class source

  Files folder image Files  /  src  /  Models  
File Role Description
  Plain text file RestAccess.php Class Class source
  Plain text file RestAccessUser.php Class Class source

  Files folder image Files  /  src  /  Repositories  
File Role Description
  Plain text file CommonRepository.php Class Class source
  Plain text file CommonRepositoryAccessProvider.php Class Class source
  Plain text file CommonRepositoryAccessProviderBase.php Class Class source
  Plain text file CommonRepositoryAccessProviderDB.php Class Class source
  Plain text file CommonRepositoryModel.php Class Class source
  Plain text file CommonRepositoryModelProvider.php Class Class source
  Plain text file CommonRepositoryModelProviderBase.php Class Class source
  Plain text file CommonRepositoryModelTrait.php Class Class source
  Plain text file Repository.php Class Class source
  Plain text file RepositoryProvider.php Class Class source
  Plain text file RepositoryProviderBase.php Class Class source
  Plain text file TraitRepositoryFilter.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:72
This week:0
All time:10,232
This week:59Up