如何获取selectRaw子句中的所有列?

时间:2016-03-18 09:59:33

标签: mysql laravel

我有一个users表并预先其中一个,有许多image对应要保存在images表中,并带有外键user_id

我想从users表中获取所有数据并计算其图像的数量,此代码正常运行:

$out = Users::join('images','images.user_id', '=', 'users.id')->selectRaw('users.id, users.name, count(*) as quantity')->groupBy('user_id')->get();

结果示例:

[{'id'=>1,'name'=>'Rome','quantity':2},
{'id'=>2,'name'=>'Rome','quantity':5},....
]

我的users表有很多列,例如:email, role等,有时我必须修复它的结构,所以我必须多次更改子句selectRaw中的字符串。< / p>

我的问题是:如何更改子句selectRaw中的字符串以获取users表中的所有列,伪代码如下:

selectRaw('* from users, count(*) as quantity')

1 个答案:

答案 0 :(得分:1)

试试这个:

$int = 999999999999999999;
$min = 1;
$max = 2147483647;

if (filter_var($int, FILTER_VALIDATE_INT, array("options"=>
    array("min_range"=>$min, "max_range"=>$max))) === false) {
    echo("Variable value is not within the legal range");
} else {
    echo("Variable value is within the legal range");
}
//This will output "Variable value is not within the legal range"