-
-
Notifications
You must be signed in to change notification settings - Fork 0
Collection
mbroersen edited this page Oct 15, 2020
·
2 revisions
import {Collection} from 'jeloquent';
Collection extends Array
User.find([1,2,3]).pluck('name');
//returns array of user names
['User 1', 'User 2', 'User 3']
User.all().first();
//returns Model
User
User.all().first();
//returns Model
User
User.find([1,2,3]).merge(User.find([4, 5, 6]));
//returns merged collection
Collection(6) [User, User, User, User, User, User]
field string name of field
operator <
|<=
|>
|>=
|==
|!=
value value of field to use operator with
User.all().whereBetween('id', '>', 5);
//returns Collection with user id greater then 5
Collection(4) [User, User, User, User];
User.all().whereIn('id', [2,4,6]);
// returns collection of users with ids 2,4,6
Collection(3) [User, User, User]
User.all().whereBetween('id', [5, 9]);
//returns Collection with user with id between 5 and 9
Collection(5) [User, User, User, User, User];
User.all().whereNull('team_id');
//returns Collection with user where field team_id has a null value
Collection(1) [User];
User.find([1,2,3]).merge(Team.find([4, 5, 6])).whereInstanceOf(User);
//returns Collection with only instances of User
Collection(3) [User, User, User];