I want to loop my packages in the table (each package has belongsToMany relationship with the test model) & I don't know how to loop in my blade?
public function tests() { return $this->belongsToMany('App\Models\Test'); }
Here is my complete form (blade):
<table> <thead> <tr> <th></th> <th><span>Child</span></th> <th>Women</th> <th>Men</th> <th>Athletes</th> <th>VIP</th> </tr> </thead> <tbody> <tr> <td class="title"><b>TestOne</b></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td></td> <td></td> <td></td> </tr> <tr> <td class="title"><b>TestTwo</b></td> <td></td> <td></td> <td><i class="fa-solid fa-check"></i></td> <td></td> <td><i class="fa-solid fa-check"></i></td> </tr> <tr> <td class="title"><b>TestThree</b></td> <td></td> <td><i class="fa-solid fa-check"></i></td> <td></td> <td></td> <td></td> </tr> <tr> <td class="title"><b>TestFour</b></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td></td> <td><i class="fa-solid fa-check"></i></td> <td></td> </tr> <tr> <td class="title"><b>TestFive</b></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td></td> <td></td> </tr> <tr> <td class="title"><b>TestSix</b></td> <td></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> <td><i class="fa-solid fa-check"></i></td> </tr> </tbody> </table>
Each <i class="fa-solid fa-check">
Displays one row of the pivot table between
The design is:
How do I loop through relational models in my blde?
If you have actually sent the list of models to the view, you can use blade directives like this (this is just a mock model, I don't know what your model actually looks like):
@if condition is just my guess. Enter whatever you need to determine whether the fa check should be rendered.
Usually sending data is to view the following content:
You can then access the variable $models
in the viewI create the table this way by checking the relationship: