【发布时间】:2013-10-15 19:14:04
【问题描述】:
我在使用 Laravel 4 查询生成器时遇到问题,我想创建一个可重用的方法
public function getData($where=array())
{
// $where = array('city' => 'jakarta', 'age' => '25');
return User::where($where)->get();
// this will produce an error, because i think laravel didn't support it
}
在 CodeIgniter 中很容易将数组传递给活动记录:
public function getData($where=array())
{
$rs = $this->db->where($where)->from('user')->get();
return $rs->result();
}
// it will produce :
// SELECT * FROM user WHERE city = 'jakarta' AND age = '25'
知道如何在 Laravel 4 查询生成器上使用它吗?我有谷歌搜索但没有找到任何答案。之前谢谢。
【问题讨论】:
-
目前还没有任何方法可以做到这一点,但最近提交了一个拉取请求。您可以在这里查看并说出您的想法:github.com/laravel/framework/pull/3108。
标签: php laravel laravel-4 query-builder