我需要在我的laravel blade文件中使用if else条件。打印不同的图标。这是我当前的刀片文件
@foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/edit" class="editInline"><i class="glyphicon glyphicon-pencil"></i></a>
<a href="" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>
</span></h4>
</div>
</li>
</ul>
<hr>
@endforeach
我需要这样一个刀片文件
@if (Auth::user()->id)->exists()) {
@foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>
</span></h4>
</div>
</li>
</ul>
<hr>
@endforeach
else
@foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/edit" class="editInline"><i class="glyphicon glyphicon-pencil"></i></a>
<a href="" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>
</span></h4>
</div>
</li>
</ul>
<hr>
@endforeach
我该怎么办?
2条答案
按热度按时间bejyjqdl1#
下面展示了如何使用if语句laravel blade
可以使用@if、@elseif、@else和@endif指令构造if语句。这些指令的功能与它们的PHP对应指令相同:
更多详情:https://laravel.com/docs/5.5/blade
j1dl9f462#
我在你的代码中发现了一些错误,比如
else
没有@
,你在first if中使用了{
,这是不应该使用的。你也错过了关闭@endif
。这里是代码