Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel/Angular: passing data within php page to angularjs

I have the following laravel html/blade page and i want to pass in a storeid that then can get picked up via angular to then use to get and do some workings with.

Below is how i am accomplishing it NOW but is there a better way to produce the same?

Blade Partial

<div ng-controller="storeChartCtrl" data-storeid="{{ $store['id'] }}">
    <p>{{ $store['name'] }} Sales</p>
    ...
</div>

Angular Ctrl

.controller('storeChartCtrl', ['$scope', 'Store', function($scope, Store){
    //-- get the requested store sales
    var storeid = JQ('#storeChart').data('storeid');

    $log.info(storeid);
    ....

This currently works and i get my storeid value so i can then send to my factory to get the data.

like image 318
Simon Davies Avatar asked Dec 12 '25 19:12

Simon Davies


1 Answers

When using Angular (or even just jQuery), I thank @JeffreyWay for this package:

https://github.com/laracasts/PHP-Vars-To-Js-Transformer

like image 66
Laurence Avatar answered Dec 14 '25 08:12

Laurence



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!