【发布时间】:2021-10-01 23:06:57
【问题描述】:
我正在处理一个膳食计划项目,为了视觉呈现,我想知道在 foreach 循环期间,每个具有唯一 MealPlan_ID 的表是否会在每个具有呈现数据的表之间出现中断(分隔)?
目前,生成的每个新膳食计划都只是添加到一个表中。
观点:
<thead>
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
ID
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Recipe Name
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Day
</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
View More
</th>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200">
@foreach ($data as $var)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
{{$var->Recipe_ID}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
{{$var->recipe_name}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
{{$var->Day}}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<a href="recipeinformation/{{$var->Recipe_ID}}" class="text-indigo-600 hover:text-indigo-900 mb-2 mr-2">More</a>
</td>
</tr>
@endforeach
</tbody>
我有两个影响表填充的数据库表,MealPlan 表和食谱表。
MealPlanDisplayController中的索引方法:
public function index(){
$currentuserid = Auth::id();
$data = Recipe::join('mealplan_main', 'mealplan_main.Recipe_ID', '=', 'recipe.id')->where('mealplan_main.user_id', '=', $currentuserid)->get(['mealplan_main.Recipe_ID', 'recipe.recipe_name', 'mealplan_main.Day']);
return view('MealPlanDisplay.index', compact('data'));
是否可以在每次使用新的膳食计划 ID 生成新的膳食计划时拆分表?如果不是,那么除了表格之外,还有什么更好的方式来呈现数据,因为我想直观地呈现彼此分开的膳食计划(因为用户可以有多个膳食计划)?
【问题讨论】: