Laravel-adminlte: Plugins initialized via adminlte.php config enhancement

Created on 23 Jun 2020  路  1Comment  路  Source: jeroennoten/Laravel-AdminLTE

| Question | Answer
| ----------------------- | -----------------------
| Issue or Enhancement | Enhancement
| Laravel Version | 7
| Project Version | 3.3.1

Current Behavior

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.

Expected Behavior

Get files loaded via adminlte.php (plugin section) to work with laravel functions.

Steps to Reproduce

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

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 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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rafayet-monon picture rafayet-monon  路  3Comments

dunfy picture dunfy  路  6Comments

bbdangar picture bbdangar  路  5Comments

santiagoferraz picture santiagoferraz  路  5Comments

vissini picture vissini  路  6Comments