users
table with a boolean flag in a subscribed
column. Additionally, you want to see the oldest subscribers first. You keep track of when a user subscribed in a subscribedDate
column. Your query might look as follows:subscribedDate
column wasn't null?User
entity for subscribed
:longestSubscribers
.scope
keyword. You call these functions without the scope
keyword (as shown above).query
, a reference to the current QuickBuilder
instance, as the first argument. Any other arguments passed to the scope will be passed in order after that.QuickBuilder
object or nothing. Doing so lets you continue to chain methods on your Quick entity. If you instead return a value, Quick will pass on that value to your code. This lets you use scopes as shortcut methods that work on a query.applyGlobalScopes
method on an entity. Inside this entity you can call any number of scopes:withoutGlobalScope
method:lastLoginDate
of a user, not the entire Login
relationship. Subselects are perfect for this use case. You can even use subselects to provide the correct key for dynamic subselect relationships. We'll show how both work here.lastLoginDate
for a User:User
entity based on the value of the subselect, so long as we've called the scope adding the subselect first (or made it a global scope).User
based on the subselect:addSubselect
helper method. Here is that function signature:true
true
logins
relationship? Or even logins().latest().limit( 1 ).get()
? Because that executes a second query. Using a subselect we get all the information we need in one query, no matter how many entities we are pulling back.lastLoginDate
for a User using the existing relationship:logins
relationship is structured, we only have one place we need to change.latestPost
relationship. This sequence will only execute two queries, no matter how many records are loaded.CASE
statement results.addSubselect
helper method.CASE
statement as a field:publishedStatus
just like any other attribute. It will not be updated, inserted, or saved though, as it is just a virtual column.appendVirtualAttribute
method adds the given name as an attribute available in the entity.true