I have something strange going on. I am trying to query with a whereNull
and also a where
statement. When i just use the whereNull
it returns results, but as soon as I add the where
statement, nothing gets returned even though there should be 2 results.
$user
->shoePurchases()
->whereNull('completed_at')
->where('status', '!=', 'failed')
->get();
The shoePurchases
relationship is a simple hasMany
2
Answers
You can do these things in order to find the problem
Review the data: Ensure that there exist shoe purchases which are not marked as "failed" and are yet to be completed. To perform this check, execute the following query directly on your database:
Remove the where clause for the status and see if you get any results. This will help you determine if the issue is with the whereNull or the where clause for the status.
Use the orWhere method: Instead of using multiple where clauses, use the orWhere method to retrieve shoe purchases that are not completed or have a status other than "failed".
In this case, I guess All purchases with status != ‘failed’ have completed_at not null