Good morning ~
I’ve tried several approaches to storing hierarchical data on the mysql/laravel end in preparation for Algolia.
The first was:
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', NULL, NULL, NULL, NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES (NULL, 'Sections', NULL, NULL, NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES (NULL, NULL, '03 01 00 Maintenance of Concrete', NULL, NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES (NULL, NULL, NULL, '03 01 30 Maintenance of Cast-in-Place Concrete', NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES (NULL, NULL, NULL, NULL, '03 01 30.51 Cleaning of Cast-in-Place Concrete');
As you can see above, the data cascades to the right in each row. When looping and populating html selects I’m trying to make a dropdown list dependent on the previous category. (another project)
@foreach($masterFormats as $masterFormat)
@if ($masterFormat->lvl_1 != NULL)
<option value="{{ $masterFormat->lvl_1 }}">{{ $masterFormat->lvl_1 }}</option>
@continue
@endif
@endforeach
The above strips NULL
values, but does not carry the upstream relationship lvl
.
At any rate, the base problem is how to store this data? Users on this app will select the categories their products belong to which will save in a record, then using scout will send the searchable array to algolia.
The end goal is the hierarchical vue instantsearch widget.
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', NULL, NULL, NULL, NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', 'Sections', NULL, NULL, NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', 'Sections', '03 01 00 Maintenance of Concrete', NULL, NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', 'Sections', '03 01 00 Maintenance of Concrete', '03 01 10 Maintenance of Concrete Forming and Accessories', NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', 'Sections', '03 01 00 Maintenance of Concrete', '03 01 30 Maintenance of Cast-in-Place Concrete', NULL);
INSERT INTO master_formats (lvl_1, lvl_2, lvl_3, lvl_4, lvl_5)
VALUES ('03 Concrete', 'Sections', '03 01 00 Maintenance of Concrete', '03 01 30 Maintenance of Cast-in-Place Concrete', '03 01 30.51 Cleaning of Cast-in-Place Concrete');
Using a loop structure, this populates the html select with '03 Concrete'
as many times as there are records.
Does algolia require on each record knowledge of the previous lvl
? e.g. lv_5
should come with the relationship of lvl_4
and that of lvl_3
and so on…? (like the last line of code above)