如何在Laravel Blade中打印属于特定任务的子任务

时间:2022-02-02 12:31:54

This is really difficult for me to wrap my head around, so please excuse me if I don't give a good enough explanation of the situation.

这对我来说真的很困难,所以如果我对这种情况没有给出足够好的解释,请原谅。

I have a table "tasks", and the only column that I'm really using for this problem is | tasks_id |.

我有一个表“任务”,我真正用于此问题的唯一列是| tasks_id |。

I created another table "subtasks", and it has these relevant columns:

我创建了另一个表“子任务”,它有这些相关的列:

| subtasks_id | subtasks_title | subtasks_tasks_id |

| subtasks_id | subtasks_title | subtasks_tasks_id |

For each row in the table "tasks", there are n rows of subtasks with a different subtasks_id but the same subtasks_tasks_id.

对于表“tasks”中的每一行,有n行子任务,具有不同的subtasks_id但是相同的subtasks_tasks_id。

I print the tasks by passing them to an array in my HomeController and looping through the array in the blade template. For every TASK, how would I also loop every SUBTASK, which has the same subtasks_tasks_id and the tasks' tasks_id?

我通过将任务传递给我的HomeController中的数组并循环遍历刀片模板中的数组来打印任务。对于每个TASK,我如何循环每个SUBTASK,它们具有相同的subtasks_tasks_id和任务'tasks_id?

Is there a way to use the ->where() clause in the blade template? I'm quite new to Laravel, also I didn't know how to word this into a google search so please do forgive my ignorance. Thank you in advanced.

有没有办法在刀片模板中使用 - > where()子句?我对Laravel很新,我也不知道如何将其写入谷歌搜索,所以请原谅我的无知。先谢谢你。

P.S. I will keep on trying to solve this unless someone gives me an answer beforehand, if I do solve it I will post my answer, if not, please don't hesitate trying to help me :P, thank you again.

附:我会继续努力解决这个问题,除非有人事先给我答复,如果我解决了,我会发布我的答案,如果没有,请不要犹豫试图帮助我:P,再次感谢你。

1 个解决方案

#1


0  

So I figured out what I had to do...

所以我想出了我必须要做的事情......

Using a multidimensional array, I can set the key to array $subtasks the | tasks_id | of any existing subtasks, then the value of each will be a corresponding array where the subtasks_tasks_id is the same as the key of the value. I then loop through each subtask by doing something like $subtask[$tasks_id][$i] where I create two outer loops (one is already created, so it shouldn't be too difficult). And now I know what to do, next step is the how, or really the actual coding, okay, that is all..

使用多维数组,我可以将键设置为$ $ subasks | tasks_id |对于任何现有的子任务,则每个子的值将是相应的数组,其中subtasks_tasks_id与值的键相同。然后我通过执行类似$ subtask [$ tasks_id] [$ i]的操作遍历每个子任务,其中我创建了两个外部循环(一个已经创建,所以它不应该太难)。现在我知道该怎么做,下一步是如何,或者真正的实际编码,好吧,这就是全部......

#1


0  

So I figured out what I had to do...

所以我想出了我必须要做的事情......

Using a multidimensional array, I can set the key to array $subtasks the | tasks_id | of any existing subtasks, then the value of each will be a corresponding array where the subtasks_tasks_id is the same as the key of the value. I then loop through each subtask by doing something like $subtask[$tasks_id][$i] where I create two outer loops (one is already created, so it shouldn't be too difficult). And now I know what to do, next step is the how, or really the actual coding, okay, that is all..

使用多维数组,我可以将键设置为$ $ subasks | tasks_id |对于任何现有的子任务,则每个子的值将是相应的数组,其中subtasks_tasks_id与值的键相同。然后我通过执行类似$ subtask [$ tasks_id] [$ i]的操作遍历每个子任务,其中我创建了两个外部循环(一个已经创建,所以它不应该太难)。现在我知道该怎么做,下一步是如何,或者真正的实际编码,好吧,这就是全部......