sorskod / larasponse
Installs: 165 222
Dependents: 0
Suggesters: 0
Security: 0
Stars: 76
Watchers: 4
Forks: 20
Open Issues: 8
Requires
- php: >=5.4.0
- illuminate/pagination: 4.2.*
- illuminate/support: 4.2.*
- league/fractal: 0.9.*
This package is not auto-updated.
Last update: 2024-11-06 14:23:31 UTC
README
NOTE: Laravel 5 is still in development but there is a working branch which support it - dev-L5. Feel free to check the code and contribute.
Larasponse
Beautiful and easy to use API responses. It uses League/Fractal as a default provider.
Installation
Add Larasponse to your composer.json file:
"require": { "sorskod/larasponse": "~1.0" }
and run composer update sorskod/larasponse
Registering the Package
Register the service provider within the providers
array found in app/config/app.php
:
'providers' => array( // ... 'Sorskod\Larasponse\LarasponseServiceProvider' )
Usage
Here is various examples in single controller:
use Sorskod\Larasponse\Larasponse; class UserController extends BaseController { protected $response; public function __construct(Larasponse $response) { $this->response = $response; // The Fractal parseIncludes() is available to use here $this->response->parseIncludes(Input::get('includes')); } public function index() { return $this->response->paginatedCollection(User::paginate()); } public function show($id) { return $this->response->item(User::find($id), new UserTransformer()); } public function collection() { return $this->response->collection(User::all(), new UserTransformer(), 'users'); } }
Read more...
- Using Fractal with Laravel to create an API by @mabasic