Support the ongoing development of Laravel.io →
Views Blade
Last updated 2 years ago.
0

In blade

{{ $something }}

is exactly equal to

<?php echo $something ?>

You can not echo an array. You have to convert it to a string before echoing. Use json_encode().

{{ json_encode(Helper::getSomething()) }}
0

Yes this works fine. But i am not achieved my result. The class prints [{"NA_LY_AVG":"3.3"},{"NA_LY_AVG":"0.83"},{"NA_LY_AVG":"0.48"},{"NA_LY_AVG":"0.66"},{"NA_LY_AVG":"0.5"},{"NA_LY_AVG":"0.34"}]

But what i want is [3.3, 0.83, 0.48, 0.66, 0.5, 0.34] like wise. Is there any other method to achieve this result.

Thanks for your help in advance.

0

If your result is a simple array you can use php's implode function like so:

$str = implode(", ", $result);

This will return a string with your results like 1, 2, 3, 4, 5. So maybe use something like this in your helper class:

$str = implode(", ", $result);

return "[$str]"; // or pass it to your view however you like

Then in the view you can just echo it normally with blade:

{{ $result }}
Last updated 9 years ago.
0

Still i am not getting the result. The view page getting stop where the class is printed. Here is the code.

class Chart { public static function OffIncRef() { $results = DB::table('dashboards')->select('NA_LY_AVG')->where('type', '=', 'Offshore-Incidents')->where('CATEGORY', '=', 'Reference')->get();

	$str = implode(", ", $results);

	return $str ;
}

}

In my view i have print like this

{{ Chart::OffIncRef(); }}

Please correct me where i am wrong.

Thanks

0
$result = DB::table('dashboards')->select('NA_LY_AVG')->where...->get();

gives a Collection. To select only the value of 'NA_LY_AVG' do

$na_ly_avg_only = $result->map(function($item){return $item->NA_LY_AVG;};

$na_ly_avg_only is also a collection.
You can echo it without json_encode or convert it to an array with ->toArray(). If you convert it to an array you have to call json_encode over it before echoing.

0

My expectation is i want to pass the data to Javascript Highcharts. Here is my code:

<script type="text/javascript">
        $(function () {
        $('#overref').highcharts({
        title: {
            text: 'Overall Incidents'
        },  
        xAxis: {
            categories: ['Team1', 'Team2', 'Team3', 'Team4', 'Team5','Team6']
        },
        labels: {
            items: [{
                html: 'Overall Incidents',
                style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]
        },
        series: [{
            type: 'column',
            name: '2013 Monthly Avg',
            data: [12, 2.6, 8.5, 6.9, 4.1, 2.5]
        }, {
            type: 'column',
            name: '2014 Monthly Avg',
            data: [7.1, 1.08, 2.4, 0.7, 2.3, 0.25]
        }, {
            type: 'column',
            name: '2015 Monthly Goal',
            data: [5.7, 0.66, 1.92, 0.66, 1.12, 0.25]
        }, {
            type: 'spline',
            name: '2015 Monthly Avg YTD',
            data: [3, 0, 0.3, 1, 0, 0],
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
                }]
            });
        });
    </script>

My eloquent model name is Dashboard.

I want to pass the data to 2013 Monthly Avg respectively.

Please help me to get this done.

0

I have found the solution for this query.

I have written Raw SQL query in my controller. Below is SQL,

$oir = DB::table('dashboards')->select('id', 'PROCESS', 'NA_LY_AVG', 'NA_CY_AVG', 'MLY_GOAL', 'AVG_YTD')->where('TYPE', '=', 'Overall-Incidents')->where('CATEGORY', '=', 'Reference')->get();

 // load the view and pass the dashboard
        return View::make('dashboard.index')
            ->with('oir', $oir);

And i have return it to the view blade.

In my view i have written like this.

        @foreach($oir as $key => $oiref)
        <?php $oir1[] = $oiref->NA_LY_AVG; 
        ?>

Then i echo that variable in data.

data: [<?php echo join($oir1, ',') ?>]

Its working fine.

Thanks

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.