Kritim Yantra
Apr 08, 2025
In Part 1, we covered the basics of integrating AdminLTE into a Laravel 12 project. Now, let’s dive deeper! In this follow-up guide, we’ll explore advanced customization, plugin integration, role-based access control, and production optimizations to build a robust, enterprise-ready admin panel.
AdminLTE’s default layout can be overridden to match your brand. Modify the master layout by copying the default file to your resources/views/layouts
directory:
cp resources/views/vendor/adminlte/master.blade.php resources/views/layouts/adminlte.blade.php
Update config/adminlte.php
to use your custom layout:
'layout' => 'layouts.adminlte',
Now, edit adminlte.blade.php
to add custom headers, footers, or scripts.
AdminLTE 3 supports dark mode. Enable it via the config:
'classes_body' => 'dark-mode', // Force dark mode
Or toggle dynamically using JavaScript in your layout file:
document.getElementById('darkModeToggle').addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
});
The jeroennoten/laravel-adminlte
package provides pre-built auth views. Scaffold them using:
php artisan adminlte:install --only=auth
This replaces Laravel’s default auth views with AdminLTE-styled ones. Test registration/login at http://localhost:8000/register
.
To redirect users to the AdminLTE dashboard after login, update app/Http/Controllers/Auth/LoginController.php
:
protected $redirectTo = '/admin/dashboard';
AdminLTE supports DataTables for dynamic tables. Install the Laravel DataTables package:
composer require yajra/laravel-datatables-oracle
Example Usage in a Blade View:
<table id="users-table" class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
</table>
@section('adminlte_js')
@parent
<script>
$(document).ready(function() {
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: '{{ route('admin.users.data') }}',
columns: [
{ data: 'id' },
{ data: 'name' },
{ data: 'email' }
]
});
});
</script>
@stop
Create a route and controller to fetch data asynchronously.
AdminLTE includes Chart.js. Add a chart to your dashboard:
In dashboard.blade.php
:
<div class="card">
<div class="card-header">
<h3 class="card-title">Monthly Sales</h3>
</div>
<div class="card-body">
<canvas id="salesChart"></canvas>
</div>
</div>
@section('adminlte_js')
@parent
<script>
const ctx = document.getElementById('salesChart').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr'],
datasets: [{
label: 'Sales (USD)',
data: [1200, 1700, 800, 2000],
borderColor: 'rgb(75, 192, 192)',
}]
}
});
</script>
@stop
Manage roles and permissions using the popular spatie/laravel-permission
package:
composer require spatie/laravel-permission
Publish migrations and run them:
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
Restrict dashboard access to users with the admin
role:
// In DashboardController.php
public function __construct()
{
$this->middleware(['auth', 'role:admin']);
}
Customize the menu in config/adminlte.php
based on roles:
'menu' => [
[
'text' => 'Dashboard',
'url' => 'admin/dashboard',
'icon' => 'fas fa-tachometer-alt',
'can' => 'access admin dashboard' // Gates or permissions
],
],
AdminLTE uses npm packages. Install dependencies and compile assets for production:
npm install
npm run build
Add @vite()
directives to your layout file to load compiled CSS/JS:
<!-- In adminlte.blade.php -->
@vite(['resources/sass/app.scss', 'resources/js/app.js'])
Optimize Laravel for production:
php artisan config:cache
php artisan route:cache
php artisan view:cache
Create a custom SCSS file at resources/sass/adminlte-custom.scss
:
// Override primary color
$primary: #4a148c;
// Import AdminLTE source
@import '~admin-lte/build/scss/adminlte';
Update vite.config.js
to include the file:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/sass/app.scss',
'resources/sass/adminlte-custom.scss', // Add this
'resources/js/app.js',
],
refresh: true,
}),
],
});
Update .env
for production:
APP_ENV=production
APP_DEBUG=false
Ensure AdminLTE’s CDN assets are used if self-hosting isn’t feasible:
// In config/adminlte.php
'cdn' => [
'enabled' => true,
'url' => 'https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/',
],
php artisan config:clear
.npm run prod
for minified assets and enable OPcache.storage
and bootstrap/cache
directories are writable.You’ve now transformed your Laravel 12 + AdminLTE integration into a polished, production-ready admin panel. By adding plugins, role-based access, and performance optimizations, your dashboard is equipped to handle real-world demands. Keep exploring AdminLTE’s documentation for even more features like calendar widgets and advanced form controls.
What’s Next?
With these tools, your admin panel is ready to scale gracefully. Happy coding! 🚀
No comments yet. Be the first to comment!
Please log in to post a comment:
Continue with Google