I'm designing a model which has these fields:
title -> VARCHAR(255)
description -> TEXT
order -> FLOAT
parent_id -> INTEGER
As you see, this model has a field named as parent_id which refers the model itself with "Belongs To" relationship. So I'm trying to make a parent-child relationship in Laravel Voyager Admin Panel.
I also want to sort these elements with their parents. Usually we set INTEGER to order field type. But this is for "1,2,3,4,5,..." sorting. I want to sort them with their parent. So it should be like "1.1, 1.2, 1.3, 1.4, 2.1, 2.2, 3.1, 3.2, 3.3, ...". I set FLOAT to order because of this reason.
But as I see, Voyager only allows to make integer-like sorting. Is there any way to sort the records of the model with float-like? I mean sorting in the admin panel.
Thanks.
I think helpful for development
in Laravel Voyager based on the provided database structure, where you have a parent_id column to establish hierarchical relationships,
you can use these steps:
like this code of model
look my controller code in this use some Sorting logic to handle sorting of elements with children elements in your controller
now you can use Voyager BREAD view to include the necessary elements for sorting. You may use Vue.js with libraries like vuedraggable to implement drag-and-drop functionality for sorting categories.
I hope you understand Thank you.