| Question | Answer
| ----------------------- | -----------------------
| Issue or Enhancement | Enhancement
| Laravel Version | 7
| Project Version | 3.3.1
When I load plugins in Javascript, the system seems not to recognize laravel functions.
For example,
If I use the url() function in a blade view inside the @section('js') and @stop tags, it works.
If I load a .js local file (plugin) via adminlte.php, the same function doesn't work.
Get files loaded via adminlte.php (plugin section) to work with laravel functions.
Step I: In a blade view inside the @section and @stop tags, try a laravel function like this:
@section('js')
<script>
var url = "{{ url('/') }}";
console.log(url);
</script>
@stop
You will see correct URL in console.
Step II: Load any .js file in plugins initializacion section inside adminlte.php with this code:
$(document).ready(function(){
var url = "{{ url('/') }}";
console.log(url);
});
You will get this _{{ url('/') }}_ or an URL with wrong characters like this _https://domain.com/%7B%7B%20url('/dashboard')%20%7D%7D_ if you try to use the var to redirect or something other url related stuff.
Anyway, good job!! the system is very useful.
Regards
Hi @reymaro0 , thanks for your suggestion. Actually, the line var url = "{{ url('/') }}"; contains blade syntax. So I'm not really sure if it will be possible to use {{ url(...) }} inside a custom Javascript file. You can read the next discussion about this:
How to use Laravel blade in a script file
However, in case you want a workaround, the best you can do is to create a new blade file, like custom_javascript.blade.php with the next skeleton:
<script>
$(document).ready(function(){
var url = "{{ url('/') }}";
console.log(url);
});
</script>
and include it in the blade file you want with @include(...) directive.
Most helpful comment
Hi @reymaro0 , thanks for your suggestion. Actually, the line
var url = "{{ url('/') }}";contains blade syntax. So I'm not really sure if it will be possible to use{{ url(...) }}inside a customJavascriptfile. You can read the next discussion about this:How to use Laravel blade in a script file
However, in case you want a workaround, the best you can do is to create a new blade file, like
custom_javascript.blade.phpwith the next skeleton:and include it in the blade file you want with
@include(...)directive.