Php 对数组laravel 5.0.35上的成员函数where()的调用
我用得上Php 对数组laravel 5.0.35上的成员函数where()的调用,php,laravel,laravel-5,Php,Laravel,Laravel 5,我用得上 public function getImages($array_symbols_id){ $array_images = DB::table('photo') ->whereIn('photo_symbol_id', $array_symbols_id) ->where('photo_moderation_id','2') ->orderByRaw('RAND()') ->ge
public function getImages($array_symbols_id){
$array_images = DB::table('photo')
->whereIn('photo_symbol_id', $array_symbols_id)
->where('photo_moderation_id','2')
->orderByRaw('RAND()')
->get(['photo_id', 'photo_src', 'photo_symbol_id']);
然后试试看
$array = array();
foreach ($array_symbols_id as $id) {
$array[] = $array_images->where('photo_symbol_id', $id)->first()->photo_src;
}
但我对数组上的成员函数where()进行了异常调用
为什么DB::table返回数组而不是集合
laravel v5.0.35在laravel 5.0中,DB返回数组,Model返回集合,因此您可以使用
collect()
将其设置为集合:
问题不在于DB::table,而在于这一行,我相信
$array\u images->where('photo\u symbol\u id',$id)
。您可能正在将集合转换为数组。。。。
$array_images = collect(DB::table('photo')
->whereIn('photo_symbol_id', $array_symbols_id)
->where('photo_moderation_id','2')
->orderByRaw('RAND()')
->get(['photo_id', 'photo_src', 'photo_symbol_id']));