dev-master
9999999-dev https://github.com/rcbytes/fetchfetch your eloquent models
MIT
The Requires
- illuminate/support ~5.1
- php >=5.3.0
The Development Requires
laravel fetch eloquent
Wallogit.com
2017 © Pedro Peláez
fetch your eloquent models
![Software License][ico-license], (*1)
Query Eloquent models easily. it is ideal for who uses Laravel as an API, (*2)
Via Composer, (*3)
``` bash $ composer require rcbytes/fetch, (*4)
On `config/app.php` Service Provider: ```php rcbytes\fetch\FetchServiceProvider::class
Facade:, (*5)
'Fetch' => rcbytes\fetch\Fetch::class
``` php ..., (*6)
class UserController extends Controller, (*7)
public function index(Request $request)
{
// your criteria will overwrite criteria from Request->where
$where = [ "account_id" => $request->user()->account_id ];
return Fetch::all(App\User::query(), $where);
}
public function show($id)
{
// third parameter $key defaults to "id"
return Fetch::one(App\User::query(), $id);
}
..., (*8)
#### Model: ```php class User implements AuthenticatableContract, CanResetPasswordContract { ... public function friends() { return $this->hasMany(\App\User::class); } public function posts() { return $this->hasMany(\App\Model\Post::class); } ... }
Get all Users with their Posts and Friends, (*9)
GET /user?with=["posts", "friends"]
Get Users with their Posts and Friends that age equals 30, (*10)
GET /user?with=["posts", "friends"]&where={age: 30}
Get Users with their Posts and their Comments and Friends that have at least one Friend with age greater than 30, (*11)
GET /user?with=["posts.comments", "friends"]&where={"friends.age":[ ">", 30]}
Get User of key = 1 with their Posts, Friends and Friends of Friends, (*12)
GET /user/1?with=["posts", "friends.friends"]
with: It expects the Models to have the relationship method. Accepts dot notation, both Models come when used. eg.: ?with:["posts.comments"]. User::posts and Post::comments methods must existwhere: It expects the Models to have the queried columns. Accepts dot notation, queries the relationship, if found at least one that matches the criteria, it returns the Model. eg.: ?where:{age: 30}, ?where:{age:[">", 30]}, ?where:{"friends.age":[">", 30]}
take: takes this number of Models
paginate: also known as per page
page: page numberPlease see CHANGELOG for more information what has changed recently., (*13)
bash
$ to do, (*14)
Please see CONTRIBUTING and CONDUCT for details., (*15)
If you discover any security related issues, please email lab.rafamello@gmail.com instead of using the issue tracker., (*16)
The MIT License (MIT). Please see License File for more information., (*17)
fetch your eloquent models
MIT
laravel fetch eloquent