PHPackages                             indatus/ranger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. indatus/ranger

ActiveLibrary[API Development](/categories/api)

indatus/ranger
==============

This package adds some power to your api rest server by allowing you to specify joins and eager loaded associations using http query parameters

0.7.0(12y ago)85357MITPHPPHP &gt;=5.4.0

Since Mar 14Pushed 12y ago3 watchersCompare

[ Source](https://github.com/Indatus/ranger)[ Packagist](https://packagist.org/packages/indatus/ranger)[ Docs](http://indatus.com/)[ RSS](/packages/indatus-ranger/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Ranger
======

[](#ranger)

[![](https://camo.githubusercontent.com/1bc853f0487bbd55575cd6cea8648b96e911f08a912834ad0804c899955caacf/68747470733a2f2f73332d75732d776573742d322e616d617a6f6e6177732e636f6d2f6f73732d617661746172732f72616e6765722e706e67)](http://indatus.com/company/careers)

The Api Base Controller is a Laravel package that allows you to get your api up and running fast. The process of creating an api can be very tedious, especially when you consider how validation, errors, and response codes will be handled. Instead of this tedium, install ranger, extend the ApiBaseController (see [examples](#examples) below), and that's it. If you feel that you want this more tailored to your needs, Ranger follows the Open/Closed principle so extending the core components is really easy.

Ranger allows for:

**Searching**
**Eager Loading**
**Joins**
**Left Joins**

Ranger also has support for both Nested and Non-nested resources. It handles Json and HTML content types but can easily be extended for other content types as well.

---

\## README Contents - [Installation](#installation)

    - [Configure in Laravel](#config-laravel)
- [Configuration Options](#config)
- [Security](#security)
- [Examples](#examples)

    - [Non-nested resource Controller](#non-nested-resource-example)
    - [Nested resource Controller](#nested-resource-example)
    - [Nested Resource Routes](#nested-resource-routes)
    - [GET Collection Example](#collection-example)
    - [GET Instance Example](#instance-example)
    - [POST Request Example](#post-example)
    - [PUT Request Example](#put-example)
    - [DELETE Request Example](#delete-example)
    - [Eager load example](#eager-load-example)
    - [Join example](#join-example)
    - [Search example](#search-example)
- [How to Solve Basic Problems](#faq)

\## Installation Install With Composer You can install the library via Composer by adding the following line to the require block of your composer.json file:

```
"indatus/ranger": "dev-master"

```

Next run `composer install`

[Back To Top](#top)

\## Configure in Laravel Currently Ranger works **Only** with the Laravel framework. However, we do have plans to make this package framework agnostic.

To publish this config to **app/config/packages/indatus/ranger** folder, you need to run the following:

```
php artisan config:publish indatus/ranger

```

The final step is to add the service provider. Open `app/config/app.php`, and add a new item to the providers array.

`'Indatus\Ranger\RangerServiceProvider'`

That's all. Now you can start using Ranger. Checkout the [**Examples**](#examples) below.

---

[Back To Top](#top)

\## Configuration Options **Ranger Settings (ranger.php)**

Ranger comes with a few configuration options. You can set the content type of the results in your api. You can also select whether you want paginated results or return the entire collection. If you want pagination, you can set the per\_page value.

SettingDefaultDescription`pagination.per_page``null`On collections, you get to decide whether you want the results paginated. A null value will return all of the results

Supported Options: `any integer` will return a paginated result ie) 25 for this config setting will return a paginated collection of 25.`content_type.default``json`Set the content type of the data. By default, it's json, but you can set this to html.

 If you would like the header to dictate what the content type to be, just set this option to null and make sure the client embeds the content type in the header ie) 'Accept' = 'application/json'

Supported Options: `html`**NOTE:** The std\_search options in this config are for future versions. Change them at your own risk, but I recommend leaving them alone for now. As we expand the searching functionality a bit, these values will be more configurable in future releases.

**All of this functionality can be achieved by just extending the ApiBaseController class.**

I'm assuming that you have taken the appropriate steps in setting up Eloquent models along with migrations.

The examples in this documentation are directly from the example app, in the repo above. Two entities are created User and Account.

[Back To Top](#top)

Examples
--------

[](#examples)

\## Non-Nested Resource Example \*\*Here's an example of a non-nested resource\*\* ```
