Download the PHP package tomhart/laravel-restful-controller without Composer

On this page you can find all versions of the php package tomhart/laravel-restful-controller. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-restful-controller

Laravel Restful Controller

Build Status codecov Scrutinizer Code Quality GitHub release (latest by date) License: GPL v3

This library adds an AbstractRestfulController to to be basic heavy lifting of a CRUD controller.

Installation

You can install this package via composer using this command:

composer require tomhart/laravel-restful-controller

Usage

If $views is empty, the specified view doesn't exist, or the Accept header is application/json, then JSON is returned

Note this also would define a blogs.show.extra, and blogs.show.options route which will be explained later.

Example response for: /blogs/1

Relationships

Loading Relationships

The show route can return your models relationships. If you send a X-Load-Relationship header, with a comma separated value list of headers to load. See the testRelationshipsCanBeReturned test for an example.

Example response for: /blogs/1 with X-Load-Relationship: comments

Accessing Relationships

You can drill into a relationship using the .show.extra route mentioned above. If the first comment had an author and you wanted to see, via the blog resources, you can call /blogs/1/comments[0]/author

You can dynamically build the route using

Restricting Access to Models

You'll most likely want to restrict access to certain models, e.g. only load the logged in users posts. To do that, there's a few methods you can overwrite.

Index Page

In order to restrict the models returned by the index route, e.g. a paginated list of many models, overwrite the createModelQueryBuilder method.

Show, Update, and Destroy Pages

In order to restrict which indiviual models can be shown, updated, or deleted, overwrite the findModel method.

Manipulating models before saving or updating

If you want to manipulate the model before they are saved, or updated, e.g. setting the user_id to the current logged in user, override the saveModel method.

Pagination

By default the index route, and any relationships it's trying to load will be paginated if possible.

Example response for: /blogs

Filtering

You can filter the index route via a query string, e.g. ?name=test.

HasLinks

This library also provides HasLinks interface, and a HasLinksTrait to provide a default implementation. If you apply those to your models, the responses will contain a _links key to help your consumers navigate around and use your API.

Example _links for /blogs/1:

The .options route mentioned earlier will simply return the index, create, and store _links for the resource so you can query the endpoint and get the URLs needing to interfacing with the API.

If you send {"id": X}, it'll also build the show, update, and delete routes with the ID supplied.

Builder

This library also includes a Builder class to interface with the API from a consumer view. It supports the standard get, insert, update, and delete methods.

Example:

To use it with your model simply add implements Restful, and use the trait InteractsWithRest


All versions of laravel-restful-controller with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
illuminate/routing Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|^7.0
illuminate/support Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|^7.0
illuminate/database Version ~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|^7.0
guzzlehttp/guzzle Version ^6.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tomhart/laravel-restful-controller contains the following files

Loading the files please wait ....