PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Raskin Veniamin   Laravel REST API   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Laravel REST API
Create an API using Laravel Eloquent models
Author: By
Last change:
Date: 2 years ago
Size: 1,934 bytes
 

Contents

Class file image Download

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