I have a problem with Laravel 4 query builder, i want make a re-usable method
public function getData($where=array())
{
// $where = array(\'city\' =>
You may try this (Assumed, this function is in your User model)
class User extends Eloquent {
public static function getData($where = null)
{
$query = DB::table('User');
if(!is_null($where )) {
foreach($where as $k => $v){
$query->where($k, $v);
}
}
return $query->get();
}
}
Rember that, = is optional. Call it like
$data = User::getData(array('first_name' => 'Jhon'));