Download the PHP package osedea/laravel-rest without Composer

On this page you can find all versions of the php package osedea/laravel-rest. 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-rest

Note

This package is no longer maintained. Should you have any issues, you are free to fork the repo.

LaravelRest

This is a Laravel 5 package that creates RESTful API routes for your models and uses the command bus to execute CRUD requests.

Installation

Install the package via composer:

composer require osedea/laravel-rest:~0.2.1

Usage

First, add the eloquence service provider to your config/app.php file:

'Osedea\LaravelRest\LaravelRestServiceProvider'

All you models need to use the trait \Osedea\LaravelRest\Traits\CommandModel to provide some attributes and methods:

Then, publish the config file to your application:

`php artisan vendor:publish --provider="Osedea\LaravelRest\LaravelRestServiceProvider"`

You should now be good to go without having to change anything! Access /api/v1/users to see a list of users!

Config Options

Application Namespace

You need to specify the application namespace used in your project. The default is App, but if you changed it, you need to change it in the config:

Models Namespace

If you models are in a custom namespace different from app_namespace, you can specify this config.

Mapping

To add a resource to the default controller, you just have to add a line in the /config/api.php file:

API Prefix

If you want to use a different prefix, you can do so by specifying the prefix key:

If you don't specify the key prefix, it will default to api.

Commands and the default controller

LaravelRest comes with a default REST controller to handle resources. This allows automatic actions on resources listing, showing, deleting and lising relations.

Actions

Method Url Command Description Options
GET /{resource} Index List resources page, perPage, sort, fields, embed
GET /{resource}/{id} Show Show one resource fields, embed
POST /{resource} Store Create a resource
PUT /{resource}/{id} Update Update a resource
DELETE /{resource}/{id} Destroy Remove a resource
GET /{resource}/{id}/{relation} RelationIndex List a resource relation page, perPage, sort, fields, embed

Options

Pagination

All lists are paginated by default. You can set a number of items per page for each Model by overriding a variable:

You can also define a maximum for this value because it can be overridden in a request:

And then in a request: /users?page=2&perPage=3

Sorting

Sorting can be done on multiple columns by separating them with commas:

/users?sort=name,email

You can choose the order (desc or asc) by putting a - in front of a column name:

/users?sort=-id

Fields

If you don't need all fields when querying a list or a resource, you can specify which fields you need:

/users?fields=id,name

Nesting

Use this only when you REALLY need to.

If you absolutely need nested relations, you specify them like so:

/users?embed=groups

Commands

Defaults

LaravelRest has default commands for several actions:

With these defaults, the mapping is enough for them to work. You can override them by creating a command using the correct namespace:

Example, to override the POST /users/{id} default command, create one called Osedea\LaravelRest\Commands\UserCommand\DestroyCommand.

Create and Update

Those actions are very specific to a resource so there is no default.

You will have to create them for all resources listed in the mapping file. The schema is this:

Osedea\LaravelRest\Commands\{mapping[resource]}Command\{action}Command

For example, to add the create command of the users resource, the command is:

Osedea\LaravelRest\Commands\UserCommand\StoreCommand

A command class

A command class needs to extend Osedea\LaravelRest\Commands\Command and implement Illuminate\Contracts\Bus\SelfHandling.


All versions of laravel-rest with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
illuminate/support Version ~5.0
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 osedea/laravel-rest contains the following files

Loading the files please wait ....