Reputation: 65
This is my model:
$AVMatchCriteria = device::where([$AVMatch])->get();
I am creating the variable $AVMatch by using a foreach loop to run through the entries in my table, below is what it looks like if I echo it out.
["category", "=", "Server"],["siteid", "!=", "145228"],["udf8", "=", "asd"]
When running my code I get the following error:
If i was to however just copy the string in plain text and put it in the model like below it works fine. I'm not sure why its not working but its putting a 0 = in my query somehow and im guessing thats the problem.
$AVMatchCriteria = device::where([["category", "=", "Server"],["siteid", "!=", "145228"],["udf8", "=", "asd"]])->get();
Any advice would be great :D
Heres how I am creating the varaible $AVMatch, I know its a little backwards but i was tinkering trying to fix it:
$AVMatch = '';
$count = 0;
foreach($AVMatchCriteria as $AV){
$count++;
if($count != $AVMatchCriteriaCount){$extra = ',[';}else{$extra = '';}
$AVMatch = $AVMatch.'"'.$AV->case.'", "'.$AV->operator.'", "'.$AV->filter.'"]'.$extra;
}
$AVMatch = '['.$AVMatch;
Upvotes: 3
Views: 118
Reputation: 65
After been informed I needed to create an array rather than a string, the code below fixed it.
$AVMatch = array();
foreach($AVMatchCriteria as $AV){
$AVMatch[] = array($AV->case, $AV->operator, $AV->filter);
}
Upvotes: 0
Reputation: 577
echo can output one or more string, not an array.
When you echo an array it should occur an error like Array to string conversion
.
But here, after echo the variable $AVMatch you got the result
["category", "=", "Server"],["siteid", "!=", "145228"],["udf8", "=", "asd"]
That means it's not an array it's a string.
You have to pass an array like
[["category", "=", "Server"],["siteid", "!=", "145228"],["udf8", "=", "asd"]]
into where clause.
But you are passing a string looks like '["category", "=", "Server"],["siteid", "!=", "145228"],["udf8", "=", "as
d"]'
Hope you understand.
Upvotes: 4
Reputation: 1844
Because you pass into where
the array which contains array with arrays.
Fix:
$AVMatchCriteria = device::where($AVMatch)->get();
Upvotes: 1