nasirkhan/laravel-cube
Laravel Cube is a set of reusable Blade UI components for Laravel with dual support for Tailwind CSS (Flowbite) and Bootstrap 5. Switch frameworks globally or per component, with dark mode and Livewire compatibility.
Installation:
composer require nasirkhan/laravel-cube
Automatically registers the service provider.
Configure Default Framework:
Set CUBE_FRAMEWORK in .env:
CUBE_FRAMEWORK=tailwind # or 'bootstrap'
Tailwind CSS Setup (if using Tailwind):
Add to resources/css/app.css:
@import "../../vendor/nasirkhan/laravel-cube/resources/css/tailwind.css";
First Use Case: Render a button in a Blade view:
<x-cube::button variant="primary">Click Me</x-cube::button>
Framework-Agnostic Development:
Use the framework prop to switch between Tailwind/Bootstrap per component:
<x-cube::button framework="bootstrap" variant="primary">Bootstrap Button</x-cube::button>
Form Handling:
Wrap inputs with <x-cube::group> for consistent validation/error display:
<x-cube::group name="email" label="Email" required>
<x-cube::input type="email" name="email" :value="old('email')" required />
<x-cube::error :messages="$errors->get('email')" />
</x-cube::group>
Modal Integration:
<x-cube::modal name="confirm">
<!-- Content -->
</x-cube::modal>
<x-cube::button x-on:click="$dispatch('open-modal', 'confirm')">Open</x-cube::button>
data-bs-* attributes for native Bootstrap modal triggers.Livewire Compatibility: Cube components work seamlessly with Livewire. Example:
<x-cube::button wire:click="save" :loading="$processing">
Save
</x-cube::button>
dark: variants.<x-cube::icon> with Flowbite icons (200+ available). Example:
<x-cube::icon name="adjustments-horizontal" class="text-blue-500" />
php artisan vendor:publish --tag=cube-config) to customize variants (e.g., button colors).Tailwind CSS Purge:
Forgetting to @import the Cube CSS file in Tailwind v4+ causes missing utility classes (e.g., buttons appear invisible). Fix: Add the import to app.css.
Bootstrap JS Dependencies: Bootstrap components (e.g., modals, dropdowns) require Bootstrap JS. Ensure you’ve included it in your layout:
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
Alpine.js Conflicts: Tailwind components use Alpine.js. If you’re not using Livewire, manually include Alpine:
<script src="//unpkg.com/alpinejs" defer></script>
Framework Mismatch:
Mixing Tailwind/Bootstrap frameworks in the same view may cause styling inconsistencies. Stick to one framework per view or use the framework prop explicitly.
dd($component) in a Blade view to inspect available props for a component.php artisan vendor:publish --tag=cube-views) and modifying resources/views/vendor/cube/components/.Custom Variants:
Extend button variants by publishing the config and adding to config/cube.php:
'tailwind' => [
'buttons' => [
'custom' => 'bg-green-600 hover:bg-green-700 text-white',
],
],
New Components:
Clone existing component views from vendor/nasirkhan/laravel-cube/resources/views/components/ and publish them.
Type Safety:
Cube uses Blade’s type system. For custom props, extend the component class in app/Providers/AppServiceProvider.php:
use NasirKhan\Cube\Components\Button;
Button::macro('customMethod', function () { ... });
How can I help you explore Laravel packages today?