Vik*_*tor 4 php laravel laravel-5
I`m use
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']);
Run Code Online (Sandbox Code Playgroud)
then try
$array = array();
foreach ($array_symbols_id as $id) {
$array[] = $array_images->where('photo_symbol_id', $id)->first()->photo_src;
}
Run Code Online (Sandbox Code Playgroud)
but i have exception Call to a member function where() on array.
Why DB::table returns an array but not a collection?
laravel v5.0.35
在 Laravel 5.0 中,DB 返回一个数组,Model 返回一个集合,因此您可以使用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']));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14008 次 |
| 最近记录: |