Php 拉威尔雄辩的选择问题

Php 拉威尔雄辩的选择问题,php,mysql,laravel,laravel-4,eloquent,Php,Mysql,Laravel,Laravel 4,Eloquent,这是我的问题 $TagDatas = TagModel::whereIn('TagId', array($BlogData->Tagged))->get(); $BlogData->taged的值为1,2,3(不是数组,而是字符) 这是我的模型 <?php class TagModel extends Eloquent { protected $primaryKey = 'AutoID'; protected $table = 'tag'; 它只显示标记表中

这是我的问题

$TagDatas = TagModel::whereIn('TagId', array($BlogData->Tagged))->get();
$BlogData->taged
的值为
1,2,3
(不是数组,而是字符)

这是我的模型

<?php
class TagModel extends Eloquent
{
    protected $primaryKey = 'AutoID';
    protected $table = 'tag';
它只显示标记表中的第一个元素

即使在调试时,它也会显示

 select * from `tag` where `TagId` in (1,2,3)

我缺少的是什么?

如果将字符串值传递给
,其中()
,当Elounce准备绑定时,它将被视为文本字符串,因此实际执行的语句将被删除

select * from `tag` where `TagId` in ('1,2,3')
您需要将每个值1、2和3作为单独的数组项传递,以便正确绑定它们

$TagDatas = TagModel::whereIn('TagId', explode(',', $BlogData->Tagged))
    ->get();
因此,where将把这三个元素视为单独的数组元素,并给出

select * from `tag` where `TagId` in (1, 2, 3)

如果
$BlogData->taged
是一个字符串,则在使用它之前将其分解为一个数组,否则它将被视为一个文本字符串。。。Laravel使用预先准备好的语句,因此bindvar将是一个字符串:语句应该是
select*from`tag`where`TagId`in(?)
,一个
1,2,3
的bindvar,我应该做$myArray=explode(',,$BlogData->taged)<代码>$TagDatas=TagModel::其中('TagId',explode(',',$BlogData->taged))->get()完成了!谢谢你能把它作为一个答案贴出来吗!因为它帮助了我
select * from `tag` where `TagId` in (1, 2, 3)