我正在Laravel中创建一个foodlog应用程序,有关如何制作食谱的说明存储在数据库中以逗号分隔的列表中,如下所示:
cook the chicken, add peppers and onions, add sauce, serve with rice
我想在我的网站上将其显示为编号列表,如:
1. cook the chicken
2. add peppers and onions
3. add sauce
4. serve with rice
我目前的字符串出现在'< p>'标签,但希望它作为编号列表。有什么想法吗?
info.blade.php
<h1>{{ $recipes->recipe_name }}<h1>
<h2>Ingredients:</h2> <p>{{ $recipes->ingredients}}</p><br>
<h2>How to:</h2> <p>{{ $recipes->description }}</p><br>
RecipesController.php
public function showinfo($id) {
$recipes = Recipes::find($id);
return view('recipes.info', compact('recipes'));
}
看起来像这样:
答案 0 :(得分:0)
希望这有帮助。
<强> info.blade.php 强>
$descriptionList = new \Illuminate\Support\Collection(explode(",", $description));
echo "<ol>";
$descriptionList->each(function($description){
echo "<li>" . $description . "</li>";
});
echo "</ol>";
或
$description = "cook the chicken, add peppers and onions, add sauce, serve with rice";
$descriptionList = explode(",", $description);
<ol>
@foreach ($descriptionList as $descriptionItem)
<li>{{ $descriptionItem }}</li>
@endforeach
</ol>
您可以将其转换为使用Laravel刀片模板。