Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garrettmassey's avatar

Make Nova Stack Field sortable by specific model column?

Say I have a model that has a 'name' and a 'description' property, and I want to display those in a stack on the Nova resource:

Stack::make('Name & Description', [
    Line::make('Name')
        ->asHeading(),
    Line::make('Description')
        ->asSmall(),
])->onlyOnIndex(),

And I want to make it sortable on the index by the 'name' column, so that we can easily sort the table for the resource by using the name without adding an additional name column.

I tried this:

Stack::make('Name & Description', [
    Line::make('Name')
        ->asHeading(),
    Line::make('Description')
        ->asSmall(),
])->sortableUriKey(function() {
    return 'name';
})->onlyOnIndex(),

but then I get the error call to a member function onlyIndex() on string

So I tried removing the onlyOnIndex() feature, but that gives me the error:

call to a member function isShownOnIndex() on string

So, is it possible to use any kind of sortable method on a stack? Specifically on a given line item in the stack?

I have also tried adding the sortable() method to the first Line::make() and I have also tried adding ->sortable() by itself to the end of the Stack::make() but neither of those works.

I can't seem to find anything in the documentation mentioning how to specify the sorting details like column name.

0 likes
1 reply
garrettmassey's avatar
garrettmassey
OP
Best Answer
Level 6

I figured it out, it wasn't very clear in the documentation, but it looks like if you have a stack where at least one of the stack line items is based on a model column, you can make the stack sortable on that column like so:

Stack::make('Name & Description', 'name', [
            Line::make('Name')
                ->asHeading(),
            Line::make('Description', function () {
                return Str::limit($this->description, 50);
            })->asSmall(),
        ])->sortable()->onlyOnIndex(),

So the above is the name and description column, and it's sortable on the name column, which is exactly what I wanted.

Please or to participate in this conversation.