Relation Querying with parameter grouping
Ad
I have the following query on a model - however the condition of querying only the teams matches applies solely to the first where clause.
$this->matches = $this->team->matches()->whereNull('wbp')->orWhere(function($q) {
$q->whereNotNull('wbp')->where('is_played','=',0);
})->get();
If I use them on their own, they are properly working - both returning exactly one Item as they should:
$this->team->matches()->whereNull('wbp')->get();
$this->team->matches()->where(function($q) {
$q->whereNotNull('wbp')->where('is_played','=',0);
})->get();
But chaining them will just give me all of the teams matches where wbp is null, as well as all matches of any team where wbp != null and is_played = false.
How do I properly chain it here?
Ad
Answer
Ad
I needed to chain the where on the matches() call:
$this->matches = $this->team->matches()->where(function ($q)
{
$q->whereNull('wbp')->orWhere(function($q)
{
$q->whereNotNull('wbp')->where('is_played','=',0);
});
})->get();
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad