Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Toolbar Bundle Laravel Package

c975l/toolbar-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    
  2. 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">
    
  3. 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') }}
    

Implementation Patterns

Common Workflows

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

  2. 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 #}
      
  3. 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
    
  4. Laravel-Specific Integration:

    • Dynamic Route Binding: Pass dynamic data to routes:
      {{ toolbar_button(route('products.destroy', ['product' => $product]), 'Delete', 'sm', false, false, 'danger') }}
      
    • Authorization: Use Laravel’s @can directive to conditionally render buttons:
      @can('update', $product)
          {{ toolbar_button(route('products.edit', $product), 'Edit') }}
      @endcan
      
  5. 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') }}
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warning: The bundle is archived and deprecated. Avoid in new projects; consider alternatives like:

  2. FontAwesome Dependency:

    • If FontAwesome icons fail to render, verify the CDN path or local asset inclusion.
    • Use the toolbar_icon() helper for custom icons:
      {{ toolbar_icon('fas fa-trash', 'Delete', 'text-danger') }}
      
  3. Route Conflicts:

    • Ensure route names (e.g., path('ROUTE')) match Laravel’s route() helper. Example:
      {{ toolbar_button(route('products.index'), 'Back to List') }}
      
    • Debug missing routes with:
      php artisan route:list
      
  4. Styling Issues:

    • Override Bootstrap classes if the toolbar’s default styles clash. Use !important sparingly:
      .toolbar-button { padding: 0.25rem 0.5rem !important; }
      
    • Clear cached views after config changes:
      php artisan view:clear
      
  5. Laravel Mix/Vite Conflicts:

    • If using Vite, ensure the toolbar’s static assets (CSS/JS) are not duplicated. Exclude the bundle’s assets from processing:
      // vite.config.js
      export default {
        assetsInclude: ['**/*.js', '**/*.css', '!**/vendor/c975l/**'],
      };
      

Debugging Tips

  1. Template Overrides:

    • Debug missing toolbar sections by checking 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/
      
  2. Route Debugging:

    • Log the generated URL to verify routes:
      {{ dump(toolbar_button(route('action'), 'Label')) }}
      
  3. Configuration:

    • Validate config/toolbar.php after publishing. Common issues:
      • Incorrect position values (e.g., fixed-top vs. fixed-bottom).
      • Missing visible_roles or visible_permissions arrays.
  4. Performance:

    • Disable the toolbar in production if unused:
      'enabled' => env('APP_ENV') !== 'production',
      
    • Lazy-load toolbar assets with defer:
      <link rel="stylesheet" href="..." defer>
      

Extension Points

  1. 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>')
    
  2. Dynamic Visibility: Use Laravel’s service container to conditionally render items:

    @if(auth()->user()->hasPermission('toolbar_item'))
        {{ toolbar_button(route('action'), 'Permitted Action') }}
    @endif
    
  3. 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,
        ],
    ];
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware