title: Passing a PHP variable to JavaScript in a Blade template
body: <p>is there any ways that JavaScript can get the variable from the controller in a Laravel Blade template?</p>
  <p>Example:
  I have the code below:</p>
  <pre class="lang-php prettyprint-override"><code>$langs = Language::all();
  return View::make('NAATIMockTest.Admin.Language.index',compact('langs'));
  </code></pre>
  <p>Can I get <code>$langs</code> and pass it to JavaScript? I already used <a href="https://github.com/laracasts/PHP-Vars-To-Js-Transformer" rel="noreferrer">PHP-Vars-To-Js-Transformer</a>. But when I use <code>JavaScript::put()</code> for two functions in the controller. It didn't work. Any help?</p>
  <p>This is my create function in the controller:</p>
  <pre class="lang-php prettyprint-override"><code>public function create()
  {
      $names = $this-&gt;initLang();
      Javascript::put([
          'langs' =&gt; $names
      ]);
      
      return View::make('NAATIMockTest.Admin.Language.create',compact('names'));
  }
  </code></pre>
  <p>this is my view:</p>
  <pre class="lang-html prettyprint-override"><code>@extends('AdLayout')
  @section('content')
  &lt;script type=&quot;text/javascript&quot;&gt;
      var app = angular.module('myApp', []);
      app.controller('langCtrl', function($scope) {
          $scope.languages = langs;
      });
  &lt;/script&gt;
      
  &lt;div class=&quot;container-fluid&quot; ng-app=&quot;myApp&quot; ng-controller=&quot;langCtrl&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-8 col-md-offset-2&quot;&gt;
              &lt;div class=&quot;panel panel-default&quot;&gt;
                  &lt;div class=&quot;panel-heading&quot;&gt;
                      &lt;h2&gt;Create language&lt;/h2&gt;
                  &lt;/div&gt;
                      
                  &lt;div class=&quot;panel-body&quot;&gt;
                      {!! Form::open() !!}
                          &lt;p class=&quot;text-center&quot;&gt;
                              {!! Form::label('Name','Language: ') !!}
                              &lt;input type=&quot;text&quot; name=&quot;searchLanguage&quot; ng-model=&quot;searchLanguage&quot;&gt;
                          &lt;/p&gt;
      
                          &lt;select name=&quot;Name[]&quot; multiple size=&quot;10&quot; ng-model=&quot;lang&quot; ng-click=&quot;show()&quot;&gt;
                              &lt;option value=&quot;@{{v}}&quot; ng-repeat=&quot;(k,v) in languages | filter:searchLanguage&quot;&gt;
                                  @{{v}}
                              &lt;/option&gt;
                          &lt;/select&gt;&lt;br&gt;
      
                          &lt;div class=&quot;text-center&quot;&gt;
                              {!! Form::submit('Create',['class'=&gt;'btn btn-primary']) !!}&amp;nbsp;
                              {!!   Html::linkAction('NAATIMockTest\LanguageController@index', 'Back', null, array('class' =&gt; 'btn btn-primary')) !!}
                          &lt;/div&gt;
                      {!! Form::close() !!}
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  @endsection
  </code></pre>
  <p>my javascript.php in config folder:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  return [
      'bind_js_vars_to_this_view' =&gt; 'footer',
      'bind_js_vars_to_this_view' =&gt; 'NAATIMockTest.Admin.Language.create',
      'bind_js_vars_to_this_view' =&gt; 'NAATIMockTest.Admin.Language.edit',
      
      'js_namespace' =&gt; 'window',
  ];
  </code></pre>
  <p>The idea is:
  I have a table language in MySQL. I want to show the dropdown list with multiple attributes to choose, and I also want to search with angularjs as well. That's why I want to pass the variable from the controller to JavaScript. Additionally, I have the function inside LanguageController called initLang to check if any language is exist inside the database, it isn't displayed inside the dropdown list in create the view.</p>