我有一个变量
2,3
..。我通过邮件传递给我的职务:
//echo $_POST['sponsored_inserts']; returns 2,3
$sponsored_link = Link::where('status', '=', 1)
->where('sponsored', 1)
->with('page', 'tag')
->inRandomOrder()
->WhereNotIn('id', [$_POST['sponsored_inserts']])
->first();WhereNotIn只从搜索中删除id 2.但是,如果我说:
$sponsored_link = Link::where('status', '=', 1)
->where('sponsored', 1)
->with('page', 'tag')
->inRandomOrder()
->WhereNotIn('id', [$_POST['sponsored_inserts'],3])
->first();起作用..。
发生什么事了呢?
发布于 2018-02-08 07:03:07
因为您的变量是一个字符串类型,如果它类似于2,3,由逗号分隔,并不意味着它是一个数组。
WhereNotIn()函数接受数组作为第二个参数,因此$_POST['sponsored_inserts'] = [2,3]是可以接受的。
你得做:
$sponsoredInserts = explode(',',$_POST['sponsored_inserts']);在你的查询中
->WhereNotIn('id',$sponsoredInserts);https://stackoverflow.com/questions/48676649
复制相似问题