我有一个相同的sql但是把一个放在模型中,一个放在控制器中,它返回不同的结果
输入控制器(结果= 2);
public function data() {
$vendor_id = $this->getVendorId ();
$menu = Menu::where('vendor_id', '=', $vendor_id)->get();
var_dump(count($menu));
}
放入模型(结果= 1);
public function data() {
$vendor_id = $this->getVendorId ();
$menu = new Menu;
$menu->getMenuByVendorId($vendor_id);
var_dump(count($menu));
}
(in model)
public function getMenuByVendorId ($vendor_id) {
$menu = Menu::where('vendor_id', '=', $vendor_id)->get();
return $menu;
}
任何人都知道这是什么问题?
答案 0 :(得分:0)
在此处更改您的代码
public function data() {
$vendor_id = $this->getVendorId ();
$menu = new Menu;
$result = $menu->getMenuByVendorId($vendor_id); // assign result in a variable and then count
var_dump(count($result));
}
答案 1 :(得分:0)
在您的模型中,将数据功能更改为:
public function data() {
$vendor_id = $this->getVendorId ();
$menu = new Menu;
$menu = $menu->getMenuByVendorId($vendor_id);
var_dump(count($menu));
}