laravel 类 Illuminate\Database\Eloquent\Collection 的对象无法转换为 int
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31250336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Object of class Illuminate\Database\Eloquent\Collection could not be converted to int
提问by Richard Hewitt
I am trying to pass data to a datatable in laravel 5 but have the following error
我正在尝试将数据传递到 laravel 5 中的数据表,但出现以下错误
Object of class Illuminate\Database\Eloquent\Collection could not be converted to int
类 Illuminate\Database\Eloquent\Collection 的对象无法转换为 int
the error line is one which corresponds to where I am selecting desired information from my model `
错误行对应于我从模型中选择所需信息的位置
$query= ChangedProperties::select('changed_property','change_type','previous_value','updated_value')->get();`
any ideas ?
有任何想法吗 ?
回答by Kiran LM
The code above returns collection object,
上面的代码返回集合对象,
$query= ChangedProperties::select('changed_property','change_type','previous_value','updated_value')->get();
$value1 = $query->changed_property;
$value2 = $query->change_type;
...
insert those variables to each of the required fields that match datatypes.
将这些变量插入到匹配数据类型的每个必填字段中。
回答by Karthiga
You should use the contains()
method that is available to you.
您应该使用您可以使用的contains()
方法。