Installation:
composer require c975l/toolbar-bundle
Add to config/bundles.php (Laravel 5.5+) or AppKernel.php (older versions):
c975L\ToolbarBundle\c975LToolbarBundle::class => ['all' => true],
Dependencies:
Ensure your project includes Bootstrap and FontAwesome via CDN or local assets. Verify in your layout file (e.g., resources/views/layouts/app.blade.php):
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
First Use Case:
Add a toolbar button in a Twig template (e.g., resources/views/products/show.blade.php):
{{ toolbar_button(path('edit_product', {'id': product.id}), 'Edit', 'md', false, false, 'primary') }}
Note: In Laravel, use route() instead of path():
{{ toolbar_button(route('products.edit', ['product' => $product]), 'Edit', 'md', false, false, 'primary') }}
Dynamic Toolbar Integration: Use the bundle in Laravel Blade templates by extending the Twig syntax:
@extends('toolbar::default') {# Extend the toolbar layout #}
Override the default toolbar partials in resources/views/vendor/toolbar/.
Button Generation:
Standard Button:
{{ toolbar_button(route('action'), 'Label', 'lg', false, false, 'success') }}
Parameters:
route: Laravel route name or URL.label: Button text.size: lg|md|sm|xs (default: md).use_another_label: Boolean to override label (e.g., for icons).use_another_style: Boolean to customize styles.color: Bootstrap color class (e.g., primary, danger).Icon-Only Button:
{{ toolbar_button(route('action'), '', 'sm', true, true, 'warning') }}
{{ toolbar_icon('fas fa-edit') }} {# Custom icon via FontAwesome #}
Toolbar Configuration: Override the toolbar’s default settings (e.g., position, visibility) by publishing the config:
php artisan vendor:publish --tag=toolbar-config
Modify config/toolbar.php to adjust:
'position' => 'fixed-top', // 'fixed-top' | 'relative' | 'static'
'visible_roles' => ['admin', 'editor'], // Restrict by user roles
Laravel-Specific Integration:
{{ toolbar_button(route('products.destroy', ['product' => $product]), 'Delete', 'sm', false, false, 'danger') }}
@can directive to conditionally render buttons:
@can('update', $product)
{{ toolbar_button(route('products.edit', $product), 'Edit') }}
@endcan
Asset Management:
Register FontAwesome and Bootstrap assets in Laravel’s app.blade.php:
@vite(['resources/css/app.css', 'resources/js/app.js'])
@stack('styles')
@stack('scripts')
Push dependencies to the stack in your toolbar views:
{{ $toolbar->addStyle('https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css') }}
Deprecation Warning: The bundle is archived and deprecated. Avoid in new projects; consider alternatives like:
FontAwesome Dependency:
toolbar_icon() helper for custom icons:
{{ toolbar_icon('fas fa-trash', 'Delete', 'text-danger') }}
Route Conflicts:
path('ROUTE')) match Laravel’s route() helper. Example:
{{ toolbar_button(route('products.index'), 'Back to List') }}
php artisan route:list
Styling Issues:
!important sparingly:
.toolbar-button { padding: 0.25rem 0.5rem !important; }
php artisan view:clear
Laravel Mix/Vite Conflicts:
// vite.config.js
export default {
assetsInclude: ['**/*.js', '**/*.css', '!**/vendor/c975l/**'],
};
Template Overrides:
resources/views/vendor/toolbar/. If the directory doesn’t exist, create it and copy the original from the bundle’s Resources/views/:
cp -r vendor/c975l/toolbar-bundle/Resources/views/* resources/views/vendor/toolbar/
Route Debugging:
{{ dump(toolbar_button(route('action'), 'Label')) }}
Configuration:
config/toolbar.php after publishing. Common issues:
position values (e.g., fixed-top vs. fixed-bottom).visible_roles or visible_permissions arrays.Performance:
'enabled' => env('APP_ENV') !== 'production',
defer:
<link rel="stylesheet" href="..." defer>
Custom Toolbar Items: Extend the toolbar by creating a new Twig function. Example:
// app/Providers/AppServiceProvider.php
public function boot()
{
Blade::directive('toolbarItem', function ($expression) {
return "<?php echo \$this->extendToolbar($expression); ?>";
});
}
Use in templates:
@toolbarItem('<button>Custom Item</button>')
Dynamic Visibility: Use Laravel’s service container to conditionally render items:
@if(auth()->user()->hasPermission('toolbar_item'))
{{ toolbar_button(route('action'), 'Permitted Action') }}
@endif
Event Integration: Trigger events when toolbar actions are clicked (e.g., for analytics):
// app/Providers/EventServiceProvider.php
protected $listen = [
'c975l.toolbar.button.clicked' => [
\App\Listeners\LogToolbarAction::class,
],
];
How can I help you explore Laravel packages today?