There are still a number of issues with your code that need to be addressed, but the reason why you're only getting the last result of the checkbox set, assuming that the checkbox values are coming from $valore = Input::get('opt');
, is because when you loop through the values in your foreach, you're overwriting your results variable.
In your code:
foreach ($valore as $val) {
$results = Tpaytv::where('Desc', 'LIKE', '%' . $val . '%')->get();
echo $val . ""; //
// echo $results
}
The variable $result
has not been declared until the first iteration of your loop which means that in your first loop $result
is set to the result of your Tpaytv::where
method call and then on the second loop the value in $result
is being overwritten by the next result from the Tpaytv::where
method call. This is why you're only getting the last value checked; it's the last value looped over in your foreach.
If you want to get a sack of results, you need to declare the $result
variable as an empty array before the foreach loop and then push the results into the array:
// Create your empty array
$results = array();
foreach ($valore as $val) {
// Push the results of the method call into the array.
// This will keep them from being overwritten in your foreach loop.
$results[] = Tpaytv::where('Desc', 'LIKE', '%' . $val . '%')->get();
echo $val . ""; //
// echo $results
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…