kole-laravel maintained by celke
celke/kole-laravel
Blade layout and components for admin systems in Laravel, with the same
look as @celke/kole-react:
collapsible sidebar, topbar with menu search, light/dark theme, density, forms
tied to old() and $errors, a table with Laravel pagination, dialogs,
confirmation and toasts.
- Laravel with Blade → this package (Composer).
- Laravel with Inertia + React →
@celke/kole-react(npm).
Both draw the same HTML (kl-* classes) and keep theme, density and sidebar
in the same browser keys, so an app with pages of both kinds looks like a
single system (see Together with Inertia + React).
Coming from 0.x? 1.0 moved the API to English, like kole-react 1.0. See Upgrading from 0.x and the CHANGELOG.
Installation
composer require celke/kole-laravel
Requirements: PHP 8.2+ and Laravel 12 or 13 (Laravel 11 is out of support and Composer refuses to install it over a security advisory). The package doesn't depend on Alpine or any other JavaScript library (it lives with Alpine, Livewire and HTMX). The Inter font and the icons (Lucide) come inside.
CSS and JS (Vite)
The CSS and JS live in the package itself, in vendor/celke/kole-laravel/resources.
The app imports them from there, without copying: composer update brings the
fixes.
/* resources/css/app.css — with Tailwind 4 (Laravel's default) */
@layer theme, base, kole, components, utilities; /* before anything else */
@import 'tailwindcss';
@import '../../vendor/celke/kole-laravel/resources/css/kole.css';
@import '../../vendor/celke/kole-laravel/resources/css/kole-react/tailwind.css'; /* optional: the bridge below */
// resources/js/app.js
import '../../vendor/celke/kole-laravel/resources/js/kole.js';
The @layer line comes before Tailwind: that way kole beats the preflight
(buttons and fields keep their style) and the utilities beat kole
(<x-kole::alert class="mt-4"> works). The tailwind.css bridge makes
Tailwind's dark: follow the kole theme and turns the tokens into utilities
(bg-surface, text-ink, text-t3, border-border, bg-primary,
rounded-card…).
Without Tailwind, the kole.css @import is enough.
Without Vite
php artisan vendor:publish --tag=kole-assets
Copies CSS, JS and fonts to public/vendor/kole:
<link rel="stylesheet" href="/vendor/kole/css/kole.css">
<script type="module" src="/vendor/kole/js/kole.js"></script>
After updating the package, run the command again with --force.
Usage
The page and the layout
{{-- resources/views/components/layouts/app.blade.php --}}
<x-kole::page :title="$title ?? null" :vite="['resources/css/app.css', 'resources/js/app.js']">
<x-kole::app-shell>
{{ $slot }}
</x-kole::app-shell>
</x-kole::page>
{{-- resources/views/users/index.blade.php --}}
<x-layouts.app title="Usuários">
<x-kole::page-header title="Usuários" icon="users" breadcrumb>
<x-slot:actions>
<x-kole::button :href="route('users.create')" icon="plus" label="Novo usuário" />
</x-slot:actions>
</x-kole::page-header>
…
</x-layouts.app>
<x-kole::page> builds the HTML document with the theme script in the
<head> (before the CSS, so whoever uses the dark theme doesn't see the light
page flash). If you already have your own <head>, use only
<x-kole::initial-theme /> in it.
<x-kole::app-shell> takes the footer, sidebarFooter and topbarExtras
slots, and props such as :brand, :environment="['label' => 'Homologação']",
version, search-action (global search URL, GET ?q=) and
:preferences="false" (hides theme/density).
Menu, user and notifications
Register them once, in a service provider of the app. The menu is built on every request (permissions and the current page change), so it also works with Octane.
use Celke\Kole\Facades\Kole;
public function boot(): void
{
Kole::menu(fn () => [
['items' => [['label' => 'Painel', 'icon' => 'house', 'route' => 'dashboard']]],
['label' => 'Cadastros', 'items' => [
['label' => 'Usuários', 'icon' => 'users', 'route' => 'users.index', 'can' => 'index-user'],
['label' => 'Tabelas', 'icon' => 'table', 'children' => [
['label' => 'Categorias', 'route' => 'categories.index'],
]],
]],
]);
Kole::user(fn ($user) => ['name' => $user->name, 'role' => $user->role?->name, 'photo' => $user->avatar_url]);
Kole::userMenu(fn () => [
['label' => 'Meu perfil', 'icon' => 'user', 'href' => route('profile.show')],
['label' => 'Sair', 'icon' => 'log-out', 'href' => route('logout'), 'method' => 'post', 'destructive' => true, 'dividerBefore' => true],
]);
// without registering them, the bell doesn't show
Kole::notifications(fn () => auth()->user()?->unreadNotifications->map(fn ($n) => [
'title' => $n->data['title'], 'time' => $n->created_at->diffForHumans(), 'unread' => true, 'href' => $n->data['url'],
])->all() ?? []);
}
Menu item keys:
| Key | What it does |
|---|---|
label |
Item text (required). |
icon |
Lucide icon name. |
route + params |
Route name. If the route doesn't exist yet, the item is dropped without error. |
href |
A ready URL (instead of route). |
children |
Group items. A group with no visible children is dropped. |
can |
Gate ability (a string, a list — needs all of them — or a closure). Without permission, dropped. |
visible |
bool or closure. |
disabled |
Shown dimmed, without a link. |
reload |
Only for kole-react (page outside Inertia). See below. |
The active item is the one with the most specific route that matches the
current page (on /orders/new, "Novo pedido" beats "Pedidos"; on
/orders/12/edit, outside the menu, the prefix still lights "Pedidos"). The
active item's group already comes open, and the breadcrumb (breadcrumb on
the header) comes from the same path: Início › Cadastros › Tabelas › Categorias.
User menu items: label, icon, href, method (post, delete… become a
<form> with CSRF), destructive, dividerBefore, target (_blank) and
confirm (confirmation message).
Forms
<x-kole::form title="Editar usuário" icon="user" :action="route('users.update', $user)" method="put"
:back="route('users.index')" :brand="'#'.$user->id" breadcrumb>
<x-kole::form-section legend="Dados pessoais" icon="user">
<x-kole::text-field name="name" label="Nome" :value="$user->name" required class="kl-col-2" />
<x-kole::text-field name="email" label="E-mail" type="email" :value="$user->email" required class="kl-col-2" />
<x-kole::select-field name="role_id" label="Perfil" :options="$roles->pluck('name', 'id')" :value="$user->role_id" />
<x-kole::password-field name="password" tooltip="Deixe em branco para manter" autocomplete="new-password" />
<x-kole::textarea-field name="bio" label="Sobre" maxlength="500" class="kl-col-full" />
<x-kole::checkbox-field name="active" label="Usuário ativo" appearance="switch" :value="$user->active" />
</x-kole::form-section>
</x-kole::form>
<x-kole::form>already adds@csrfand@method, opens with the same header card aspage-header, and the footer shows "N campo(s) a corrigir" when validation comes back with errors.- Each field takes the value from
old()(after an error) or fromvalue, and the error from$errors.nametakes a dot:address.citybecomesaddress[city]. - The password never comes back filled.
classgoes on the field frame (widthskl-col-2,kl-col-3,kl-col-full; the grid has 4 columns,:columnson the section changes it). The other attributes (placeholder,maxlength,autocomplete,disabled…) go on the control.- The checkbox sends
0when unchecked (a hidden input before it);:unchecked-value="false"removes it. read-onlydisables everything and removes Save;filessends uploads (multipart).- For a control of your own, use the frame:
<x-kole::field label="Cor" for="cor" :error="$errors->first('cor')">…</x-kole::field>.
Table and pagination
<x-kole::table label="Usuários" :paginator="$users" :per-page="[10, 20, 50]" empty-title="Nenhum usuário">
<x-slot:header>
<x-kole::table-sort column="name">Nome</x-kole::table-sort>
<th scope="col">E-mail</th>
<th class="kl-table-col-actions" scope="col"><span class="kl-sr">Ações</span></th>
</x-slot:header>
@foreach ($users as $user)
<tr>
<td class="is-featured">{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td class="kl-table-col-actions">
<div class="kl-table-actions">
<x-kole::row-action icon="pencil" label="Editar" :href="route('users.edit', $user)" />
<x-kole::row-action icon="trash-2" label="Remover" severity="danger" method="delete"
:href="route('users.destroy', $user)" :confirm="'O usuário '.$user->name.' será removido.'" />
</div>
</td>
</tr>
@endforeach
</x-kole::table>
Pagination takes paginate() and simplePaginate(). To use the kole look on
the whole app's ->links(): Paginator::defaultView('kole::pagination.laravel').
table-sort and per-page only build the links (?sort=name&direction=asc,
?per_page=20). The controller validates the values before using them
(in_array($column, ['name', 'email'])): never pass what comes from the URL
straight to orderBy or paginate.
Messages, confirmation and dialogs
return redirect()->route('users.index')->with('sucesso', 'Usuário salvo.');
// or: ->with('erro', ['title' => 'Não foi possível salvar', 'detail' => 'Tente de novo.'])
The session keys that become a toast are in config('kole.flash')
(sucesso, success, status, info, aviso, warning, erro, error).
They are the app's own keys, so the Portuguese ones stay.
Confirmation before submitting, on any <form>, button or link:
<form method="POST" action="{{ route('users.destroy', $user) }}"
data-kl-confirm="O usuário será removido." data-kl-confirm-title="Remover usuário?"
data-kl-confirm-label="Remover" data-kl-confirm-severity="danger">
Dialog:
<x-kole::button label="Novo" icon="plus" data-kl-open="novo-usuario" />
<x-kole::dialog id="novo-usuario" title="Novo usuário" icon="user-plus" :open="$errors->any()">
<form id="form-novo" method="POST" action="{{ route('users.store') }}">@csrf …</form>
<x-slot:footer>
<x-kole::button label="Cancelar" severity="secondary" data-kl-close />
<x-kole::button type="submit" form="form-novo" label="Salvar" icon="save" />
</x-slot:footer>
</x-kole::dialog>
The dialog traps the focus, closes on Esc and on the mask, and gives the focus
back to whoever opened it. In JavaScript: Kole.toast({ severity: 'success', title: 'Salvo' }),
await Kole.confirm({ title: 'Remover?', severity: 'danger' }),
Kole.openDialog('id'), Kole.setTheme('dark'). For HTML that arrives later
(HTMX, fetch), Kole.start(element) applies the initial state.
Page loading
Every link and form loads a whole new page. When the next page takes more than
200 ms, kole.js shows the blocking <x-kole::loading> (spinning ring in the
middle of the screen) until it arrives. Nothing to set up: it comes with kole.js.
- It covers same-origin links (left click, no Ctrl/Cmd/Shift), forms (also after
data-kl-confirm), clickable table rows and cards (data-href) and calendar events withhref. - It skips new tabs (
target="_blank", Ctrl+click),download, a#hashon the same page, other sites and clicks another script cancelled (preventDefault). data-kl-no-loadingon a link, form, submit button or any ancestor turns it off; on<html>, for the whole app. Put it on links and forms that download a file (export, PDF): the page doesn't change, so the loading would stay up to its 30 s limit.data-kl-loading-logo="/img/logo.svg"on<html>shows the logo in place of the ring.- The backdrop is lighter than a dialog's and fades in, so the screen doesn't
blink dark between pages.
--kl-page-loading-backdropchanges it (transparentkeeps only the panel). - It hides on Esc and when the browser brings the page back from the history
cache. For navigations started by your own JS:
Kole.pageLoading.start()andKole.pageLoading.done().
Components
| Group | Components |
|---|---|
| Page | page, initial-theme, app-shell, page-header, breadcrumb, login-screen, welcome, error-screen |
| Actions | button (with href it becomes a link), row-action, button-group, button-toolbar, close-button |
| Form | form, form-section, field, text-field, password-field, textarea-field, select-field, checkbox-field, currency-field, state-field, person-type-field, rating |
| Data | table, table-sort, pagination, card, card-list, list, list-item, details, stat, stat-group, status, badge, chip, avatar, empty-state, icon, money, amounts, hide-amounts-button, license-plate |
| Content | quote, code-block, image, figure, collapsible |
| Feedback | alert, dialog, confirm, toasts, progress, spinner, loading, skeleton |
Names and props follow kole-react (severity, appearance, label,
icon…). Blade differences: React functions become URLs and forms (href,
action, method), and fields use name + value instead of value +
onChange. A tooltip on any element: data-kl-tooltip="text". button-group
doesn't hand severity/appearance down to its buttons (Blade has no context
for it): set them on each button. A collapsible opens with any
data-kl-toggle="its-id" element.
Sizes that come from data (a skeleton width, a progress percentage, an avatar
size) never go into an inline style: the component prints data-kl-vars and
kole.js applies them, so a strict CSP keeps working.
Money and currency
<x-kole::currency-field name="price" label="Preço" :value="$product->price" />
<x-kole::currency-field name="price_usd" label="Preço em dólar" currency="USD" />
<x-kole::currency-field name="price_eur" label="Preço em euro" currency="EUR" />
<x-kole::amounts storage-key="balance-hidden">
<x-kole::money :value="$balance" size="accent" /> <x-kole::hide-amounts-button />
<x-kole::money :value="8900" type="income" strong /> {{-- +R$ 8.900,00 in green --}}
<x-kole::money :value="320" currency="USD" type="expense" /> {{-- −US$ 320,00 in red --}}
</x-kole::amounts>
currency-field is typed from the right (cents first) and sends the number in
name (1234.56), ready for a numeric rule and a decimal column. The symbol
follows pt-BR (R$, US$, €). money takes type (income, expense,
neutral), colorize, currency, compact (R$ 1,3 mi) and size; inside
amounts, the eye hides and shows every amount. In PHP, the same formatting is
in Celke\Kole\Format::currency().
Icons: the Lucide name (icon="save", icon="trash-2"), the same 117
registered in kole-react. For others: Icons::register(['rocket' => '<path d="…"/>'])
with the content inside the <svg> from lucide.dev.
Theme and tokens
Every color and size comes from the kole tokens (CSS variables). To change the
brand, redefine them in the app's CSS, which sits outside the kole layer and
always wins:
:root {
--primary: #0f766e;
--primary-ink: #115e59;
}
[data-theme='dark'] {
--primary: #2dd4bf;
--primary-ink: #5eead4;
}
Default theme and density are in config/kole.php
(php artisan vendor:publish --tag=kole-config), along with the brand
(KOLE_BRAND_NAME, default APP_NAME, and KOLE_BRAND_SUBTITLE), the
environment band and the version. The version is automatic: the version of the
app's composer.json, then of its package.json, then the newest git tag, shown at
the foot of the sidebar and on the login screen. To set it in the deploy, use
KOLE_VERSION=2.3.1; to hide it, null in the config. People change theme and
density in the topbar and the
choice stays in the browser (kl-preferences, the same key as kole-react).
App element rules (a { color }, h1 { … }) also reach the components,
because CSS outside a layer beats the kole layer: scope those rules (for
example, .article-content h1).
Security
- All text goes through Blade's escaping (
{{ }}), including menu labels, the user name, session messages and toasts created by the JS (textContent, neverinnerHTML). - URLs that come from data (menu, profile, notifications, logo) go through
Celke\Kole\Url: only relative paths,http(s),mailtoandtel.javascript:anddata:become#. - Actions that change data (Sign out, Remove) are
<form method="POST">with CSRF, never aGETlink. Links withtarget="_blank"getrel="noopener noreferrer". - An icon only comes from the package registry (an unknown name renders no HTML).
- CSP without
'unsafe-inline': no component uses inlinestyleoron*. The two scripts that run before the paint (theme and sidebar) carry theVite::useCspNonce()nonce; without a nonce, useKOLE_SCRIPTS=fileandvendor:publish --tag=kole-assetsto load them as files (script-src 'self'). The JS doesn't useeval, so it works without'unsafe-eval'. - Videos under a CSP: the
video-playerin Vimeo mode needsframe-src https://player.vimeo.com; a file on S3 needs the bucket's address inmedia-src. The Vimeo mode only accepts messages from the player's own iframe and origin.
Together with Inertia + React
In an app with Blade pages and Inertia pages, each page uses its own technology's layout, with the menu defined only once, here:
// app/Http/Middleware/HandleInertiaRequests.php
public function share(Request $request): array
{
return [...parent::share($request), 'menu' => Kole::menuForInertia()];
}
menuForInertia() returns the menu already filtered (routes and permissions)
in the nav format of kole-react's AppShell. Mark the Blade pages with
'reload' => true: in React the link becomes a plain <a> and opens with a
full reload (Inertia's <Link> only works for Inertia pages). Theme, density
and collapsed sidebar use the same keys in both. Use kole-react 1.0 with
kole-laravel 1.0: the 0.x versions use the lp- classes.
Upgrading from 0.x
1.0 renames components, props, values, slots, CSS classes, data-*
attributes, PHP methods and the JS API to English. The full list is in the
CHANGELOG. The views are migrated by kole-react's
kole-migrate, which reads .blade.php:
npx -p @celke/kole-react@1 kole-migrate # dry run: lists what would change
npx -p @celke/kole-react@1 kole-migrate --write # applies
composer require celke/kole-laravel:^1.0 # only afterwards
What the script can't see (PHP arrays and calls) keeps working until 2.0:
the 0.x keys (rotulo, filhos, rota…), values (ok, err, escuro…),
a published 0.x config/kole.php, the old method names (Kole::usuario()…)
and class names (Celke\Kole\Icones…) are read and converted. Then check by
hand what the script lists under "To check by hand", the URL parameters your
controllers read (sort, direction, per_page) and your own CSS that
targets lp- classes.
Customizing the HTML
php artisan vendor:publish --tag=kole-views
Copies the views to resources/views/vendor/kole, and the app becomes their
owner (it stops getting the package's fixes in those files). Prefer
customizing through the tokens and CSS.
Development
composer install
composer test # PHPUnit + Orchestra Testbench
composer serve # documentation site at http://127.0.0.1:8001
composer serve opens the package's documentation site, the same as
kole-react's demo, running inside the package (Orchestra Testbench workbench):
each component page has the summary, the usage, live examples with their Blade
code and the props read from the component's @props. The CSS and JS come
straight from resources/, so a change shows on reload, with no build. The
files follow kole-react's demo:
| kole-react (demo/) | kole-laravel (workbench/resources/views/) |
|---|---|
docs/pages/components/button.tsx |
docs/components/button.blade.php |
docs/examples/button/Colors.tsx |
docs/examples/button/colors.blade.php |
docs/pages/Installation.tsx |
docs/guides/installation.blade.php |
pages/ui/Alerts.tsx |
pages/ui/alerts.blade.php |
The menu (workbench/config/docs.php) and the page titles and summaries
(workbench/config/docs-pages.php) are the same as kole-react's; a page shows
in the menu once its view exists.
The CSS (resources/css/kole-react/) and the icons (resources/icons/lucide.php)
are copied from kole-react, which is the visual reference. A visual change is
born there and arrives here with:
npm run build --prefix ../kole-react # in kole-react's sibling folder
node scripts/sync-kole-react.mjs # KOLE_REACT=/other/path for another folder
Blade-only rules live in resources/css/blade.css. A class or structure change
in a kole-react component calls for adjusting the matching Blade component.
Publishing a new version: record it in the CHANGELOG and create
the tag (git tag v1.0.1 && git push origin v1.0.1). Packagist reads the
version from the tag; within 1.x, a new version doesn't break the API.
Author
Created by Cesar Szpak.
License
MIT © 2026 Celke — see the LICENSE file.