Skip to content
Advertisement

Nested Loop in Edit Form Blade Laravel

I have an edit form that used rowspan table and nested loop. I also have a create data form that works fine like this. I used Laravel 8 for this project.

Create form

But when I’m adding the value from database to create the edit form:

Edit form -1 Edit Form -2

I get the sasaran, indikator, and data (questions) from database and then loop it with nested loop. FYI, I have 3 sasaran’s data, 12 indikators’ data, and 47 questions data that need to load with the rowspan. But when I create the edit form, the rowspan is not fit with the sasaran, indikator, or, question amount, but it loops for 47 times. The rowspan only works for the every first data of sasaran, and then doesn’t work for the rest (like the Edit Form -1) and also duplicate the data.

FYI, I didn’t used Ajax for create and edit form.

This is the code:

View:

JavaScript

Controller:

JavaScript

Sasaran Model:

JavaScript

Indikator’s Model:

JavaScript

Pertanyaan’s Model:

JavaScript

Data Laporan’s Model:

JavaScript

Laporan Indikator’s Model:

JavaScript

I’m really sorry for my bad English, but I’m really appreciate your help. Thank you.

Update: I tried to do this in my view to fix the rowspan, but the question is looping for 47 times for every sasaran and indikator (I mean, not fit with amount of its sasaran and indikator), and the amount of indikator is not fit with the sasaran. You can take a look to the Create form view that I attached for the example view that I want. I think I know where’s the problem is, but I don’t really know how to fix it. Please help me because I’m still a beginner. Thank you.

Code for new View:

JavaScript

New View -1 New View – 2

Advertisement

Answer

After trying for some times, finally I found the solution. I just add the variable $data_laporans like this:

JavaScript

I also change the relationship between DataLaporan and Pertanyaan:

DataLaporan Model:

JavaScript

Pertanyaan Model:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement