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']);
then try
        $array = array();
    foreach ($array_symbols_id as $id) {
        $array[] = $array_images->where('photo_symbol_id', $id)->first()->photo_src;
    }
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
In Laravel 5.0, DB returns an array and Model returns collections, so you can make it a collection by using 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']));
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With