You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Create single postdata.post.create({title: 'Lorem ipsum'})// Create multiple postsdata.post.create([{title: 'Lorem ipsum 1'},{title: 'Lorem ipsum 2'}])
update(id, data?)
Type
Name
Default
Description
mixed
id
null
Id of object to update
object
data
null
Data used to update record
// Update all objectsdata.post.update({title: 'Lorem ipsum 1'})// Update single object with given IDdata.post.update(14,{title: 'Lorem ipsum 1'})// Update multiple objectsdata.post.update([[14,{title: 'Lorem ipsum 1'}],[15,{title: 'Lorem ipsum 1'}]])// Update all objects matching querydata.post.where('status','in',['draft','deleted']).update({title: 'Lorem ipsum 1'})
updateOrCreate(attributes, values)
Type
Name
Default
Description
object
attributes
null
Attributes used to match object to update
object
data
null
Data used to update record
// Get first tag with name 'ship' or create it// Second param holds additional data assigned to objectdata.tag.updateOrCreate({name: 'ship'},{created_by: 1})
delete(id)
Type
Name
Default
Description
mixed
id
null
Id of object to delete
// Delete all postsdata.post.delete()// Delete signle post with given IDdata.post.delete(55)// Delete multiple postsdata.post.delete([55,56,57])// Delee all posts where draft column is equal 1data.post.where('draft',1).delete()
list()
// Get all objects from classdata.post.list()// Get all objects with status equal publisheddata.post.orderBy('created_at','DESC').where('status','published').list()
first()
// Get first postdata.post.first()// Get first draft postdata.post.where('status','draft').first()
firstOrFail()
// Get first draft post or throw exceptiondata.post.where('status','draft').firstOrFail()
firstOrCreate(attributes, values)
Type
Name
Default
Description
object
attributes
null
Attributes used to match object
object
data
null
Data used to create record
// Get first tag with name 'ship' or create it// Second param holds additional data assigned to objectdata.tag.firstOrCreate({name: 'ship'},{created_by: 1})
find(id)
Type
Name
Default
Description
mixed
id
null
Id of object to find
// Get object by IDdata.posts.find(1)// Get objects with given IDsdata.posts.find([4,5,10])
findOrFail(id)
Type
Name
Default
Description
mixed
id
null
Id of object to find
// Get object by ID or faildata.posts.findOrFail(1)// Get objects with given IDs or fail if at least one is missingdata.posts.findOrFail([4,5,10])
where(column, operator?, value)
All filtered columns must have filter_index: true:
// Get all posts with views = 100data.posts.where('views','=',100).list()// You can ommit second param to simply check if value is equaldata.posts.where('views',100).list()// Get all post with views greater than 100// Other selectors: <, <=, >, >=, =, !=data.posts.where('views','>',200).list()// Get all posts with one of the statusesdata.posts.where('status','in',['draft','published']).list()// Get all posts with id not in given arraydata.posts.where('id','nin',[10,20]).list()// Get all published posts with id between 100 and 200data.posts.where([['id','gt',100],['id','lt',200]['status','published']]).list()
orWhere(column, operator?, value)
Type
Name
Default
Description
mixed
column
null
Name of column being filtered
string
operator
'eq'
Operator user to filter
mixed
value
null
Expected value
// Get posts with views counter lower than 100 or higher than 1000data.posts.where('views','<',100).orWhere('views','>',1000).list()
whereNull(column)
Type
Name
Default
Description
string
column
null
Name of column being filtered
// Get posts without titledata.posts.whereNull('title').list()
whereNotNull(column)
Type
Name
Default
Description
string
column
null
Name of column being filtered
// Get posts with titledata.posts.whereNotNull('title').list()
// Get all not published or draft postsdata.posts.whereNotIn('status',['published','draft']).list()
whereBetween(column, min, max)
Type
Name
Default
Description
string
column
null
Name of column being filtered
mixed
min
Minimal value
mixed
max
Maximal value
// Get all posts with views between 100 and 1000data.posts.whereBetween('views',100,1000).list()// Get all posts created in last seven daysdata.posts.whereBetween('created_at',newDate(newDate().getTime()-7*24*60*60*1000).toISOString(),newDate().toISOString()).list()
with(relations)
Type
Name
Default
Description
mixed
relations
null
Relations, references which should be eager loaded
// Get object with expanded author and all commentsdata.posts.with('author','comments').list()// You can also wrap arguments in arraydata.posts.with(['author','comments']).list()
// Order posts ascending by datedata.posts.orderBy('created_at').list()// Order posts descending by datedata.posts.orderBy('created_at','desc').list()
skip(count)
Type
Name
Default
Description
number
count
null
How many object should be skipped
// Skip 10 first posts and get the restdata.posts.skip(10).list()
take(count)
Type
Name
Default
Description
number
count
null
How many object be returned
// Get only first 15 objectsdata.posts.take(15).list()
fields(columns)
Type
Name
Default
Description
mixed
columns
null
Names of columns to whitelist
// Get all posts. Result will be array of objects with keys: id, title.data.posts.fields('id','title').list()// You can also change column namesdata.posts.fields('id','user.first_name as author').list()
pluck(column)
Type
Name
Default
Description
string
column
null
Column name of which values will be returned
// Get array of post idsdata.posts.pluck('id')
value(column)
Type
Name
Default
Description
string
column
null
Column name of which value will be returned
// Get first post and return it's iddata.posts.value('id')
count()
// Count all postsdata.posts.count()// Count posts with given statusdata.posts.where('status','in',['draft','deleted']).count()