Warp

Reorganise product categories by dragging, in Filament

4 min read

A wholesaler of packaging and fasteners has grown its range. Tape used to be one of the packaging categories; now there are glues, sealants and tape, and they belong together under a new "Adhesives" group. Labels and Boxes are always ordered together, so the buyer wants them as one category.

In most admin panels that means opening each category's edit form and changing a "Parent" select, then fixing the products of a deleted category by hand, one by one. Nobody can see the whole tree while doing it, and nobody knows afterwards who moved what.

This article does the same with Warp Tree: the whole tree on one page, a new category added under Packaging, Tape dragged into it, and Labels merged into Boxes with its products. All pictures are from the live demo.

The scene: the tree on one page

The categories page shows the tree. Groups have a folder icon, the categories with products under them a tag. The badges count what is under each item: "4 items" under a group, "3 products" in a category.

A tree of product categories in Filament: Fasteners with 4 items open, showing Bolts, Nuts, Screws and Washers, then Janitorial, Packaging, Safety and Tools; a search box above
The product categories. Only the opened branches are read, so a tree of 50,000 items opens as fast as this one.

Step 1: a tree page for the resource

The categories table only needs a parent_id column. The page is a TreePage, and it replaces the resource's list page. This is the demo's page, without its "View code" button:

use Filament\Support\Icons\Heroicon;
use Qalainau\FilamentWarpTree\Pages\TreePage;
use Qalainau\FilamentWarpTree\Support\TreeRecords;

class CategoryTree extends TreePage
{
    protected static string $resource = CategoryResource::class;

    // "Export CSV" and "Import CSV" above the tree
    protected static bool $hasCsvActions = true;

    public function getTreeIcon(Model $record, bool $hasChildren): string|BackedEnum|Htmlable|null
    {
        return $hasChildren ? Heroicon::OutlinedFolder : Heroicon::OutlinedTag;
    }

    // The products filed under each category: counted in the tree,
    // and moved along when a category is merged or deleted
    public function getTreeRecords(): array
    {
        return [TreeRecords::make(Product::class, 'category_id')->label('product|products')->canBeEmpty()];
    }
}
// CategoryResource
public static function getPages(): array
{
    return [
        'index' => CategoryTree::route('/'),
    ];
}

Run php artisan migrate once for the history table. Your own tables are not changed.

Step 2: add "Adhesives" under Packaging

Hover over Packaging and press +. The new item goes under it.

A modal titled New product category under Packaging, with Name filled in as Adhesives, and Create and Cancel buttons
Adding a category under Packaging.

Step 3: drag Tape into it

Grab the handle on the left of Tape and drop it in the middle of Adhesives. Dropping on the upper or lower edge of an item puts it before or after it instead.

Tape is being dragged and is held over Adhesives under Packaging; the dragged row is shown faded
Tape on its way into Adhesives.
After the move: Adhesives under Packaging is now a folder with 1 item, and Tape with 3 products is inside it
Adhesives turned into a folder the moment something was put under it. Tape's three products came along.
Open Packaging, drag Tape, drag Labels.

The keyboard works too: Alt + → puts an item under the one above it, Alt + ↑ ↓ moves it among its siblings.

Step 4: merge Labels into Boxes

Merging is not a drag: it moves the products and the items under Labels to Boxes, then deletes Labels. The window says exactly that before anything happens. The target is chosen from a tree select, so it also works when the target is far away in a large tree.

A modal: Merge Labels into another item. Everything in Labels (2 products) moves to the item you choose. Then Labels is deleted. Merge into: Packaging › Boxes
Merging Labels into Boxes. The two products move with it.

Deleting works the same way: it asks what happens to the items under it and where the products go.

Step 5: who changed what

History lists the changes, newest first, with who made them and when.

Changes to the tree: Moved Tape from Packaging to Adhesives; Added Adhesives under Packaging
The history of the tree.

How it stays correct

  • Someone else moved it first. If another person moved Tape after your page was opened, your move is refused and the branches are read again. The page never keeps showing a stale tree.
  • No loops. An item can't be moved or merged into its own branch.
  • Permissions come from the resource: adding needs canCreate(), moving and renaming canEdit(), merging and deleting canDelete().
  • One transaction per change: if a model event stops a save, nothing is changed and a notice says so.

Other scenes

  • Departments, with the employees moved along when two departments are merged.
  • A chart of accounts or document folders.
  • A menu of three levels: protected static ?int $maxDepth = 3; refuses anything deeper, while dragging and again on the server.
  • People who see only their branch: a regional manager edits only the stores under their region.

The same package also has the pieces around the tree: a SelectTree field to pick a category in the product form, the path Packaging › Adhesives › Tape in tables, and a filter for "this branch and everything under it".

Limits worth knowing

  • Without an order column (getTreeOrderColumn()), items are listed by name, and dragging only changes the parent. Add an order column to let people set the order.
  • A depth limit added later does not move items that are already deeper; they can be moved up, not further down.

Try it

Open the categories demo, open Packaging and drag Tape somewhere else. Then merge two categories and look at History. No sign-up, and the data is reset every hour.

More from the blog

See who is free next week and book them, in Filament

An agency manager needs 40 hours for a project that starts Monday. The planner shows only the people who have the time, the booking is a drag, and the overbooked project manager gets a fix in two clicks.

Laravel Rust vs Laravel Go vs Laravel PHP: The Complete Real-World Benchmark Guide

We benchmarked Laravel Rust, Laravel Go v0.1.0, and Laravel PHP (FPM, FrankenPHP, Swoole, Workerman) across 8 real workloads on the exact same machine — from 1,000-user spikes and heavy ORM to 100k-row deep pagination. Continuously updated as new tests land.

Work through support tickets without leaving the list, in Filament

A support agent opens a ticket, assigns it, sets it to pending and moves on to the next one with the arrow key. The list stays on the left; the View and Edit pages you already have open on the right.

Filament + AI coding tips, by email

How to fit Warp plugins into your own app and pair them with Claude Code or Cursor: prompts that work, mistakes AI makes, real examples. Once or twice a month. Unsubscribe anytime.

Ask us anything about Warp

No email address or sign-up needed.

We read every question and answer here on the site, usually within a day. Others see your question after we have checked it.

What's stopping you from using Warp's plugins?

One question. We read every answer, and it decides what we build next. It is not shown on the site.

What's stopping you from using Warp's plugins?