jeroennoten / Laravel-AdminLTE

Easy AdminLTE integration with Laravel
MIT License
3.83k stars 1.09k forks source link

[QUESTION] How to use plugins with asset=true configuration? #1218

Closed kevince09 closed 1 year ago

kevince09 commented 1 year ago

I just installed Datatables Plugins and use this config :

'Datatables' => [
    'active' => false,
    'files' => [
        [
            'type' => 'js',
            'asset' => true,
            'location' => 'datatables/js/jquery.dataTables.min.js',
        ],
        [
            'type' => 'js',
            'asset' => true,
            'location' => 'datatables/js/dataTables.bootstrap4.min.js',
        ],
        [
            'type' => 'css',
            'asset' => true,
            'location' => 'datatables/css/dataTables.bootstrap4.min.css',
        ],
    ],
],

Here is my test blade code :

@extends('adminlte::page')

@section('plugins.Datatables', true)

@section('title', 'Dashboard')

@section('content_header')
    <h1>Dashboard</h1>
@stop

@section('content')
    <table class="table table-bordered" id="test_dt">
        <thead>
            <tr>
                <th>Key</th>
                <th>Value</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
@stop

@section('js')
    <script>
        $("#test_dt").DataTable();
    </script>
@stop

As it mentions on https://github.com/jeroennoten/Laravel-AdminLTE/wiki/Plugins-Configuration, when you use asset=>True the css & script location will be using laravel asset(), but it does not work on my case.

On my page, it generates :

http://xxx/datatables/css/dataTables.bootstrap4.min.css
http://xxx/datatables/js/jquery.dataTables.min.js
http://xxx/datatables/js/dataTables.bootstrap4.min.js 

When it should be :

http://xxx/vendor/datatables/css/dataTables.bootstrap4.min.css
http://xxx/vendor/datatables/js/jquery.dataTables.min.js
http://xxx/vendor/datatables/js/dataTables.bootstrap4.min.js 

I have not changed my project ASSET_URL, because the other css & script is generated correctly like this :

http://xxx/vendor/jquery/jquery.min.js
http://xxx/vendor/bootstrap/js/bootstrap.bundle.min.js
http://xxx/vendor/overlayScrollbars/js/jquery.overlayScrollbars.min.js
http://xxx/vendor/adminlte/dist/js/adminlte.min.js

So, am i using this config wrong, if so how to use this config properly ? Of course i can just use the exact path on the location like this '/vendor/datatables/js/jquery.dataTables.min.js', but i think if i can use the config as it mentions on the wiki, it will be better.

dfsmania commented 1 year ago

@kevince09 I think the asset() method usually points to the public folder within your Laravel application. So, use of '/vendor/datatables/js/jquery.dataTables.min.js' will be alright. You can check source code at https://github.com/jeroennoten/Laravel-AdminLTE/blob/master/resources/views/master.blade.php as a reference, there vendor is prepended to all urls when using the asset() method.

kevince09 commented 1 year ago

Okay, i just misunderstood the asset() and the example from wiki after all. I thought it will points to public/vendor by default (or when using this package) and assume the default code is like this :

<script src="{{ asset('jquery/jquery.min.js') }}"></script>
<script src="{{ asset('bootstrap/js/bootstrap.bundle.min.js') }}"></script>
<script src="{{ asset('overlayScrollbars/js/jquery.overlayScrollbars.min.js') }}"></script>

But i forgot that, of course you can place css folder directly under public directory, and vendor is just another directory like css from the example.

Thank you @dfsmania