Db::select Statement Return StdClass

- 1 answer

What i want to do is very simple.

I retrieve my values from database with below statement :

$result=DB::select("select day from viewholiday where year='{$year}' and month='{$month}'");

then flatten it to get ONLY values from array (as db::select return array stdClass)

 $flattenedresult = Arr::flatten($result);

then on my view i want to check if variable 'i' which keeps loop index is in this array (they must be integers. Because As you can understand from code it returns values of days like 3 means 3rd day of the month and so on ...)

@if(in_array($i, $flattenedresult)) <th id="holiday">{{$i}}. Day</th>

BUT it gives below error and can't figure out how to solve this issue.

Facade\Ignition\Exceptions\ViewException Object of class stdClass could not be converted to int



Solved it with adding pluck . Below statement give the values of column 'day' in array :

$result=DB::table('viewholiday')->where('year', $year)->where('month', $month)->get()->pluck('day')->toArray();