我在Blade laravel 5中进行查询时遇到问题
@foreach($dates_chart_debit as $date)
<?php
$result = DB::table('productions')
->join('durees', 'productions.duree_id', '=', 'durees.id')
->where(DB::raw("Date(productions.date)") ,"=",$date)
->where('productions.puit_id' ,"=",1)
->where(DB::raw("durees.isInReport") ,"=",'1')
->where('final_validation' ,"=",'1')
->select(DB::raw("sum(debit) as debit"))->first()->get();
?>
{{$result->debit}}
@endforeach
它给我一个错误信息,如
Object of class stdClass could not be converted to string (View: C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\projects\Coil\resources\views\panel\chart\executive.blade.php)
什么是最好的方法
答案 0 :(得分:0)
您的问题来自$ date变量 - 您正在尝试将对象传递给查询并将其转换为字符串。
您的评论
$ dates_chart_debit的值是数组:3 [0 =&gt; {#235 +&#34; date&#34;:&#34; 2016-07-14&#34; } 1 =&gt; {#236 +&#34; date&#34;:&#34; 2016-07-20&#34; } 2 =&gt; {#237 +&#34; date&#34;:&#34; 2016-07-29&#34; }]
确认这一点。
如果您更换了:
from = seq(1,100, 10)
aa <- length(url)
func1 = function(url){
out <- tryCatch(
{
aa <<- aa -1
print(aa)
doc = htmlParse(url)
address= as.data.frame(xpathSApply(doc,'//div[@class="panel-body"]', xmlValue, encoding="UTF-8"))
page = cbind(address,url)
if (aa %in% from){
pg = suppressMessages(melt(cc))
write.csv(pg,paste("bcc_",aa,".csv"))
}
}
cc = lapply(url, func1)
使用:
->where(DB::raw("Date(productions.date)") ,"=",$date)
有效吗?
另外 - 你能做dd($ date);对我来说好吗?
答案 1 :(得分:0)
我使用Chart Js
当我尝试设置$ date的默认值时,它没有显示任何内容未声明HTML文档的字符编码。如果文档包含US-ASCII范围之外的字符,则对于某些浏览器配置,文档将显示不正确的字符。必须在文档或传输协议中声明编码字符页。
var areaChartData = {
labels: [
@if(isset($dates_chart_debit))
@foreach( $dates_chart_debit as $dd)
"{{$dd->date}}",
@endforeach
@endif
],
datasets: [
@if(isset($puits_chart_debit ))
@foreach($puits_chart_debit as $puit)
{
label: "{{$puit->code}}",
fillColor: "{{$puit->color}}",
strokeColor: "{{$puit->color}}",
pointColor: "{{$puit->color}}",
pointStrokeColor:"{{$puit->color}}",
pointHighlightFill: "#fff",
pointHighlightStroke: "{{$puit->color}}",
data: [
@foreach($dates_chart_debit as $date)
<?php
$result = DB::table('productions')
->join('durees', 'productions.duree_id', '=', 'durees.id')
->where(DB::raw("Date(productions.date)") ,"=",$date->date)
->where('productions.puit_id' ,"=",1)
->where(DB::raw("durees.isInReport") ,"=",'1')
->where('final_validation' ,"=",'1')
->select(DB::raw("sum(debit) as debit"))->first()->get();
dd($result->debit);
?>
@endforeach
]
},
@endforeach
@endif
]
};
&#13;