php - Laravel-Lighthouse scopes are not updated
Get the solution ↓↓↓I have a query on Lighthouse which is using@paginate
scope with another 3 scopes
This is my query
profiles(where: _ @whereConditions(columns: ["email"])): [User!]! @paginate(scopes: ["byOrganizationLoggedIn","byMatchingRole", "byAvailableMatching"]) @middleware(checks: ["auth:api"])
And those are my scopes from User entity.
/**
* @param [type] $query
*/
public function scopeByOrganizationLoggedIn($query)
{
if ($organization = request()->user()->organization_id) {
$query->where('organization_id', $organization);
}
}
/**
* @param [type] $query
*/
public function scopeByMatchingRole(Builder $query)
{
if (request()->user()) {
$query->whereHas('roles', function ($q) {
$q->whereIn('name', ['Mentor', 'Mentee']);
});
}
}
/**
* @param [type] $query
*/
public function scopeByAvailableMatching(Builder $query)
{
if (request()->user()) {
$query->whereDoesntHave('matchedProfiles', function (Builder $q) {
$q->where('user_id', request()->user()->id);
});
}
}
The problem is that my last scopebyAvailableMatching
is not called and if I remove one of the other scopesbyOrganizationLoggedIn
orbyMatchingRole
it's still going into the entity methods.
I've tried to reset the lighthouse cache using
php artisan lighthouse:clear-cache
But the query and the scopes are not updated and they are returning the same data.
I'm new to Laravel and Lighthouse and if you have any suggestions to filter the query by all the scopes let me know.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreach() argument must be of type array|object, null given
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.