Laravel 6.0+AdminLTE Boilerplate环境下InfyOm DataTables配置失败求助
Hey there, let’s walk through where things might have gone wrong with your DataTables setup for InfyOm Boilerplate in Laravel 6.0. I’ve worked through similar headaches before, so here’s a breakdown of possible gaps in your process:
1. Verify Package Versions & Installation
First, double-check that you’re using the correct package versions compatible with Laravel 6.0. InfyOm’s boilerplate for Laravel 6 relies on specific versions of the DataTables ecosystem:
yajra/laravel-datatables-oracle:^9.0yajra/laravel-datatables-buttons:^4.0yajra/laravel-datatables-html:^4.0
Open your composer.json to confirm these versions are listed. If not, update them and run:
composer update
This ensures all dependencies are properly resolved—sometimes a plain composer install might miss version-specific fixes.
2. Confirm Service Provider & Alias Setup
You mentioned adding service providers and aliases, but let’s make sure they’re the right ones and placed correctly in config/app.php:
Providers Array:
Yajra\DataTables\DataTablesServiceProvider::class, Yajra\DataTables\ButtonsServiceProvider::class, Yajra\DataTables\HtmlServiceProvider::class,
Aliases Array:
'DataTables' => Yajra\DataTables\Facades\DataTables::class, 'DataTablesHtml' => Yajra\DataTables\Html\Facades\Html::class, 'DataTablesButtons' => Yajra\DataTables\Buttons\Facades\Buttons::class,
Don’t forget to publish the DataTables configuration files—this step is easy to miss:
php artisan vendor:publish --tag=datatables
3. Double-Check InfyOm Generator Configs
You updated config/infyom/laravel_generator.php to set 'add_on.datatables' => true, but you also need to confirm the scaffold-specific config in config/infyom/scaffold.php:
'datatables' => [ 'enabled' => true, 'buttons' => true, 'html' => true, ],
If this section was still set to false, the scaffold generator would ignore DataTables entirely, even if the main generator config was correct.
4. Frontend Asset Compilation & Inclusion
DataTables needs frontend CSS/JS files to render properly. First, publish the DataTables assets:
php artisan vendor:publish --tag=datatables-assets
Then, check your resources/views/layouts/app.blade.php to ensure these assets are included (InfyOm should add them automatically, but sometimes it doesn’t):
<!-- DataTables CSS --> <link rel="stylesheet" href="{{ asset('vendor/datatables/css/dataTables.bootstrap4.min.css') }}"> <!-- DataTables JS --> <script src="{{ asset('vendor/datatables/js/jquery.dataTables.min.js') }}"></script> <script src="{{ asset('vendor/datatables/js/dataTables.bootstrap4.min.js') }}"></script> <script src="{{ asset('vendor/datatables/js/dataTables.buttons.min.js') }}"></script> <script src="{{ asset('vendor/datatables/js/buttons.bootstrap4.min.js') }}"></script>
Finally, recompile your frontend assets with Laravel Mix:
npm run dev
5. Validate Scaffold-Generated Code
After re-running php artisan infyom:scaffold Test, check two key files:
1. Controller (app/Http/Controllers/TestController.php)
The index method should handle AJAX requests for DataTables:
public function index(Request $request) { if ($request->ajax()) { $data = Test::latest()->get(); return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){ // Action button HTML here }) ->rawColumns(['action']) ->make(true); } return view('tests.index'); }
If it’s just returning a view without the AJAX check, the generator didn’t pick up your DataTables config.
2. View (resources/views/tests/index.blade.php)
There should be a DataTables initialization script at the bottom:
$(document).ready(function() { $('#tests-table').DataTable({ processing: true, serverSide: true, ajax: "{{ route('tests.index') }}", columns: [ { data: 'id', name: 'id' }, // Other columns matching your Test model { data: 'action', name: 'action', orderable: false, searchable: false } ] }); });
6. Clear All Caches
Sometimes old cache files block config changes from taking effect. Run all these commands to be thorough:
php artisan config:clear php artisan cache:clear php artisan view:clear composer dump-autoload
Work through these steps one by one, and you should get DataTables working with your InfyOm scaffold. Let me know if any of these checks uncover the issue!
内容的提问来源于stack exchange,提问作者Lex

