return $this->hasMany('App\Person','type_id'); }public function getCourses() { return $this->belpngsToMany('App\Course','PeopleType_Courses','people_type_id','course_id'); } 我的尝试:$peopleType = \App\PeopleType::FindOrFail(1); $courses = $peopleType->getCourses()->whereNot...
高效写法 $users=User::whereNotIn('id',function($query)use($user){$query->select('toUserId')->from('relation')->where('relation.userId',$user->id);}); 低效率写法 $actionRelationsArray=Relation::select('toUserId')->where('userId',$user->id)->get()->pluck('toUserId');$users=...
在Laravel中,whereNotIn是一个用于构建SQL查询的方法,用于指定一个字段不在给定值列表中的条件。 具体来说,whereNotIn方法接受两个参数:第一个参数是要查询的字段名,第二个参数是一个数组,包含了不希望出现在查询结果中的值。 使用whereNotIn方法可以轻松地构建出不包含特定值的查询条件,例如: 代码语言:txt 复制...
Laravel 有很多 WhereNotIn 查询PHP ibeautiful 2022-07-22 15:56:06 问题:我正在尝试查询 PeopleType 以查找与人员无关的所有课程。我有 4 张桌子人们人员类型培训班People_CoursesPeopleType_Courses我有以下关系人物模型public function getPeopleType() { return $this->belongsTo('App\PeopleType','type_id'...
您可以使用whereNotIn方法简单地按照给定数组中未包含的键值过滤集合。 它基本上与whereIn相反。 此外,此方法在匹配值时使用宽松比较==。 让我们过滤$collection,其中user_id既不是1也不是2的。 $collection->whereNotIn('user_id', [1, 2]); AI代码助手复制代码 ...
在laravel中使用whereNotIn时参数编号无效 、 我想在我的刀片式服务器上打印数据库中的选项列表,我想要获得除已经选择的选项之外的所有列表。因此,我所做的就是将选定的选项(保存在另一个表中)作为一个数组: $ctg_id[] = []; $ctg_id[] = [$item->category_id]; } 最后打印出来: $category = ItemCat...
Laravel Eloquent 的条件不等于 方法一: 使用Eloquent的where where('id','!=', 2) 方法二: 使用Eloquent的whereNotIn ->whereNotIn('id', [2]) 参考文献: Eloquent - where not equal to MySQL query: where field is not equal to some of the given values...
//count qualified students who have father with id $fatherID//problem lays here$getSelectedStudent = \App\StudentRegistrars::where('status', 'Qualified')->whereHas('father_registrars', function($q) use($fatherID) { $q->where(...
你可以使用php implode来帮助你:
这怎么可能,whereNotIn()再加上whereIn()不等于总数?运行这个:$updatedBreeds = [ 86, 113, // etc ...];DB::enableQueryLog();dump(Breed::count());dump(Breed::whereIn('id', $updatedBreeds)->count());dump(Breed::whereNotIn('id', $updatedBreeds)->count());dd(DB::getQueryLog())...