gpt4 book ai didi

php - Laravel 5.1 Blade(或只是简单的回显)错误地显示类

转载 作者:可可西里 更新时间:2023-11-01 00:54:55 24 4
gpt4 key购买 nike

我的 Laravel (5.1) View 中有以下代码。 PHP block 中的代码决定我应该将哪个类应用于下面的第一个 td 元素。

@foreach($datesUnavailable as $dateUnavailable)
<?php
$unavailableDate = strtotime($dateUnavailable->unavailable_on);
$creationDate = strtotime($dateUnavailable->created_at);
$newformat = date('D, M d, Y',$unavailableDate);

$createdBefore = ($unavailableDate - $creationDate)/86400;

if($createdBefore >= 5) {
$class = "alert alert-success";
} else if ($createdBefore < 5 && $createdBefore >= 3) {
$class = "alert alert-warning";
} else {
$class = "alert alert-danger";
}
?>
<tr>
<td class={{ $class }}>{{ $newformat }}</td>
<td>{{ $dateUnavailable->unavailability_type }}</td>
<td>
{!! Form::open([
'method' => 'DELETE',
'route' => ['delete-unavailability', $alias, $dateUnavailable->uc_key],
'onsubmit' => 'return submitResult();'
]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach

但是,当页面呈现时,td 元素上的类显示为

<td class="alert" alert-success="">Wed, Feb 28, 2018</td>

也就是说,我希望它显示 class="alert alert-success"(基于逻辑),但它显示了这个奇怪的字符串。如果我执行 var_dump($class),我会看到 $class 变量的值是“alert alert-success”。

知道为什么会这样吗?

最佳答案

添加缺少的 " 标记。

@foreach($datesUnavailable as $dateUnavailable)
<?php
$unavailableDate = strtotime($dateUnavailable->unavailable_on);
$creationDate = strtotime($dateUnavailable->created_at);
$newformat = date('D, M d, Y',$unavailableDate);

$createdBefore = ($unavailableDate - $creationDate)/86400;

if($createdBefore >= 5) {
$class = "alert alert-success";
} else if ($createdBefore < 5 && $createdBefore >= 3) {
$class = "alert alert-warning";
} else {
$class = "alert alert-danger";
}
?>
<tr>
<td class="{{ $class }}">{{ $newformat }}</td> <!-- Changed this line -->
<td>{{ $dateUnavailable->unavailability_type }}</td>
<td>
{!! Form::open([
'method' => 'DELETE',
'route' => ['delete-unavailability', $alias, $dateUnavailable->uc_key],
'onsubmit' => 'return submitResult();'
]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger btn-xs']) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach

关于php - Laravel 5.1 Blade(或只是简单的回显)错误地显示类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48871994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com