laravel - 使用 Blade 在 foreach 循环中嵌套 if 语句
问题描述
我是 Laravel 刀片的新手,并试图在循环中嵌套一个if
语句。foreach
我想根据表中的字段是否等于显示不同的链接Submitted
。在我看来,我编写了以下代码:
@foreach($plans as $plan)
<tr>
<td> {{$plan->id}}</td>
{{-- If the Plan Submission has been submitted, the link should bring the user to the Show function which is view only. Cannot have user editing Plan Submission after it has been submitted. --}}
@if ({{$plan->status}}=='Submitted')
<td><a href="/basicinfo/{{$plan->id}}/show">Click Here</a></td>
@else
<td><a href="/basicinfo/{{$plan->id}}/edit">Click Here</a></td>
@endif
我收到此错误:语法错误
unexpected '<'
解决方案
改成:
@foreach($plans as $plan)
<tr>
<td> {{$plan->id}}</td>
{{-- If the Plan Submission has been submitted, the link should bring the user to the Show function which is view only. Cannot have user editing Plan Submission after it has been submitted. --}}
@if ($plan->status == 'Submitted')
<td><a href="/basicinfo/{{$plan->id}}/show">Click Here</a></td>
@else
<td><a href="/basicinfo/{{$plan->id}}/edit">Click Here</a></td>
@endif
它是@if ({{$plan->status}}=='Submitted')
不需要{{ }}
内部 if 语句:)
@if ({{$plan->status}}=='Submitted')
所以总的变化是:
@if ($plan->status == 'Submitted')
推荐阅读
- python - 在python中将基目录更改为上层目录
- angular - ERR_CONNECTION_REFUSED 在 Docker 容器内的 nginx 上托管的 Angular 应用程序上?
- android - Android:Kotlin 将数据从 Dialog 传递到 BottomSheetDialogFragment
- reactjs - Chartjs:仅使用 yAxis 零刻度绘制图表
- reactjs - 在运行时更新另一个组件中的一个组件的输入值
- heroku - 我无法在 Infomaniak (www.infomaniak.com) 管理的自定义拥有的域上托管我的 heroku 应用程序
- java - 应用程序代码外的 Android RuntimeException
- c# - C# 将 ListView 导出为 CSV
- c++ - 如何加载同一家族的多种字体
- mysql - 添加新行时列名与 SQL 函数冲突