Installation:
composer require andcarpi/laravel-popper
For Laravel ≥5.5, skip manual service provider/facade registration (auto-discovery handles it).
Include Assets:
Add @include('popper::assets') before </body> in your Blade view (or master layout) to load Popper.js/Tippy.js dependencies.
First Tooltip: Use the facade directly in an HTML element:
<button {{ Popper::pop('Hello!') }}>Hover Me</button>
Or via the Blade directive:
<span @popper("Hello!")>Hover Text</span>
Dynamic Tooltips: Pass dynamic content (e.g., from controllers) to tooltips:
<a href="{{ route('profile') }}" {{ Popper::pop("Welcome, {$user->name}!") }}>
Profile
</a>
Reusable Components: Create a Blade component for consistent tooltips:
@component('components.tooltip-button', ['text' => 'Save', 'tip' => 'Save changes'])
@endcomponent
<!-- components/tooltip-button.blade.php -->
<button {{ Popper::pop($tip) }}>{{ $text }}</button>
Conditional Tooltips: Use Blade logic to toggle tooltips:
@if(auth()->check())
<button {{ Popper::pop('Logged in as ' . auth()->user()->name) }}>
User Menu
</button>
@endif
Asset Optimization:
@include('popper::assets') only in views needing tooltips (not globally).resources/views/vendor/popper/assets.blade.php for production.Integration with JavaScript: Trigger tooltips programmatically via JavaScript:
document.querySelector('[data-popper]')._tippy.enable();
Asset Loading Order:
@include('popper::assets') is placed after the closing </body> tag.</body>.Duplicate Assets:
@include('popper::assets') calls load Popper.js/Tippy.js multiple times, increasing bundle size.@include in a master layout or check for existing assets with @if(!app()->bound('popper.assets.loaded')).Blade Directive Scope:
@popper directive may not work in non-Blade templates (e.g., .html files).{{ Popper::pop() }}) for non-Blade files or preprocess templates.Conflicts with Other Libraries:
data-tippy attributes or namespace tooltips:
{{ Popper::pop('Tip', ['theme' => 'my-theme']) }}
Deprecated Methods:
tippy.defaults.animation = 'fade';
Check Console for Errors:
F12) to verify Popper.js/Tippy.js loads without errors (e.g., 404 for assets).Inspect Rendered HTML:
data-popper attributes. Verify they’re rendered correctly in the DOM.Disable Other Tooltips:
$(document).off('mouseenter', '[data-toggle="tooltip"]');
Custom Tippy.js Options: Override default Tippy.js settings via the facade:
{{ Popper::pop('Custom Tip', [
'theme' => 'light',
'delay' => 200,
'arrow' => true
]) }}
Global Configuration: Publish the config file (if available) to customize defaults:
php artisan vendor:publish --provider="andcarpi\Popper\PopperServiceProvider"
(Note: The package may not include a publishable config; check the repo for updates.)
Extend with JavaScript: Add custom Tippy.js plugins or modify behavior post-render:
document.addEventListener('DOMContentLoaded', () => {
tippy('[data-popper]', {
content: 'Dynamic content!',
onShow(instance) { console.log('Tooltip shown!'); }
});
});
Localization: Use Laravel’s localization features to support multi-language tooltips:
{{ Popper::pop(__('messages.tooltip')) }}
How can I help you explore Laravel packages today?