呼叫成员函数 where// 在阵列中 laravel 5.0.35

我用


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 返回一个数组,模型返回集合,因此您可以使用它
collect//

:


$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']//;

要回复问题请先登录注册