riki's avatar
Level 21

Run action with collection sorted

Is it possible to run action in Laravel Nova with collection sorted as is in Laravel Nova's interface listing? For example I sort items by variable symbol ascending but action is processed with collection ordered by id descending) even if in POST request the data are in correct order.

0 likes
5 replies
vincent15000's avatar

I'm not sure to understand what you mean.

$collection->sortBy(...) ?
riki's avatar
Level 21

I mean sortBy() with query params of request (column name + asc/desc).

1 like
vincent15000's avatar

@riki I don't know Nova, but can't you handle this in the controller ? When you click on a column name, you send a request with the column name and the order (asc or desc).

jigar_dhulla's avatar

Never tried.

But I think it should be possible only if Nova is passing this(column name + asc/desc) information to Action. You can check ajax request passed to Action.

If yes, you can set hidden fields and on action submission you can process accordingly.

1 like

Please or to participate in this conversation.