0
votes

I have a problem when i make a query in 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

it gives me an error message like

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)

and what is the best way to do that

2
What does var_dump($result); show?Chris
the problem in the query i remove {{$result->debit}} and the same errorMohamed Amine
I'm asking what output of var_dump($result) is - it will help debug the issue...Chris
the same error 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)Mohamed Amine
What is the value of $date ?Jerodev

2 Answers

0
votes

Your issue is coming from the $date variable - You are attempting to pass an object into the query and convert it to a string.

Your comment

the value of $dates_chart_debit is array:3 [ 0 => {#235 +"date": "2016-07-14" } 1 => {#236 +"date": "2016-07-20" } 2 => {#237 +"date": "2016-07-29" } ]

Confirms this.

If you replaced the:

->where(DB::raw("Date(productions.date)") ,"=",$date)

with:

->where(DB::raw("Date(productions.date)") ,"=",2016-07-14)

Does it work?

Also - Can you do dd($date); for me please?

0
votes

I use Chart Js

when i try to put default value of $date it show me nothing The character encoding of the HTML document was not declared. The document will be displayed with incorrect characters for some browser configurations if the document contains characters outside the US-ASCII range. Encoding page of characters must be stated in the document or in the transfer protocol.

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
                    ]
            };