我有一个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')
答案 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"