If you are to use an operator the where function takes three arguments: first the name of the column, second is an operator, and third is value to compare against.
Change your condition to appear as below
->where('element_value.p_id', '=', $a->p_id)
// or, because you are making an exact match, do this
->where('element_value.p_id', $a->p_id)
The code you have at the moment is getting confused because you are telling Laravel you are making a multiple where condition, through the use of an array as the where first argument.
Laravel then takes the value of that array and tries to convert it to column, operator, and value - the way it does for the above snippet.
If you really want to use an array, you'd need to do the following:
->where([
['element_value.p_id', '=', $a->p_id]
])
// or, because you are making an exact match, do this
->where([
['element_value.p_id', $a->p_id]
])
Notice how we passed two sets of arrays?
That's because Laravel either wants each argument separate, or an array-of-arrays containing the correct signature.
For a more detailed answer; the signature looks like this
public function where($column, $operator = null, $value = null, $boolean = 'and')
If $column
is an array, it is assumed that an array-of-arrays is passed into the method, and each sub array, will effectively be spread across the above signature.
As you were passing a single array to the method, Laravel was taking the value of 4
and then using that as the $column
.
This is because you used a key-value for that array, so the column name that you had used was actually being ignored.
The other interesting thing about this method, is that it has the following snippet:
// If the given operator is not found in the list of valid operators we will
// assume that the developer is just short-cutting the '=' operators and
// we will set the operators to '=' and set the values appropriately.
if ($this->invalidOperator($operator)) {
[$value, $operator] = [$operator, '='];
}
This allows us to not pass in an operator, and Laravel will just assume that we want an =
to be used instead.
That's how I was able to omit it from my above examples.