Laravel - 雄辩的数组位置

sha*_*rgy 0 arrays where-clause laravel eloquent

我试图根据文档执行此查询,但它返回错误array_key_exists(): The first argument should be either a string or an integer

https://laravel.com/docs/5.8/queries#where-clauses

 $imagessize = $galleryObj->photos->where([
                ['gallery_id','=', $gallery->id],
                ['delete','=',0],
            ])->sum('filesize');
Run Code Online (Sandbox Code Playgroud)

Pia*_*zzi 5

where方法不接受数组,如果您愿意,您应该使用whereIn方法:

whereIn方法验证给定列的值是否包含在给定数组中:

例如:

users = DB::table('users')
                ->whereIn('id', [1, 2, 3])
                ->get();
Run Code Online (Sandbox Code Playgroud)

这将返回 id 为 1,2 和 3 的用户。

但就你而言,我认为你不需要那个。试试这个:

$imagessize = $galleryObj->photos->where('gallery_id',$gallery->id)->where('delete', 0)->sum('filesize');
Run Code Online (Sandbox Code Playgroud)