is there any ways that JavaScript can get the variable from the controller in a Laravel Blade template?
Example: I have the code below:
$langs = Language::all[];
return View::make['NAATIMockTest.Admin.Language.index',compact['langs']];
Can I get $langs
and pass it to JavaScript? I already used PHP-Vars-To-Js-Transformer. But when I use JavaScript::put[]
for two functions in the controller. It didn't work. Any help?
This is my create function in the controller:
public function create[]
{
$names = $this->initLang[];
Javascript::put[[
'langs' => $names
]];
return View::make['NAATIMockTest.Admin.Language.create',compact['names']];
}
this is my view:
@extends['AdLayout']
@section['content']
var app = angular.module['myApp', []];
app.controller['langCtrl', function[$scope] {
$scope.languages = langs;
}];
Create language
{!! Form::open[] !!}
{!! Form::label['Name','Language: '] !!}
@{{v}}
{!! Form::submit['Create',['class'=>'btn btn-primary']] !!}
{!! Html::linkAction['NAATIMockTest\LanguageController@index', 'Back', null, array['class' => 'btn btn-primary']] !!}
{!! Form::close[] !!}
@endsection
my javascript.php in config folder: