Laravel bootstrap 弹出窗口中的 Carbon 日期格式很奇怪
Laravel Carbon date format weird in bootstrap popover
我在 Laravel 视图 (blade) 中显示日期差异。我可以显示两个日期之间的时间如下:
$lengthOwned = Carbon\Carbon::now()->diffForHumans(new Carbon\Carbon($real_asset->real_owned_since));
echo($lengthOwned);
echo
语句在我的页面上正确显示此信息,将 {{$lengthOwned}}
放在 blade 中的任何位置也是如此。它显示为:
4 months after
对于 01/03/2018 和今天 05/11/2018 之间的差异
但是,我需要在 bootstrap 弹出窗口中显示它,当我这样做时,我得到了数字,没有附带的文本。因此,在弹出面板中我得到的不是“4 months after
”,而是“4
”。这意味着“4 months after
”和“12 years after
”变成了“4
”和“12
”——不好。
我的弹出框代码是:
<a href="#RE" data-toggle="popover" title="How long since acquired" data-content={{$lengthOwned}}>CLICK FOR TIME LAPSED</a>
与以下 javaScript:
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
有人对 carbon-provided 文本为什么是 missing/truncated 有任何建议吗?
我 运行 Laravel 5.5,PHP 7 XAMPP Windows 10
提前致谢。
您缺少 data-content
值的引号,现在您有:
<a data-content={{$lengthOwned}}>CLICK FOR TIME LAPSED</a>
这将呈现如下内容(将 data-content
的值设置为 4 并添加两个奇怪的属性):
<a data-content=4 months later>CLICK FOR TIME LAPSED</a>
而是将整个值用引号引起来:
<a data-content="{{$lengthOwned}}">CLICK FOR TIME LAPSED</a>
我在 Laravel 视图 (blade) 中显示日期差异。我可以显示两个日期之间的时间如下:
$lengthOwned = Carbon\Carbon::now()->diffForHumans(new Carbon\Carbon($real_asset->real_owned_since));
echo($lengthOwned);
echo
语句在我的页面上正确显示此信息,将 {{$lengthOwned}}
放在 blade 中的任何位置也是如此。它显示为:
4 months after
对于 01/03/2018 和今天 05/11/2018 之间的差异
但是,我需要在 bootstrap 弹出窗口中显示它,当我这样做时,我得到了数字,没有附带的文本。因此,在弹出面板中我得到的不是“4 months after
”,而是“4
”。这意味着“4 months after
”和“12 years after
”变成了“4
”和“12
”——不好。
我的弹出框代码是:
<a href="#RE" data-toggle="popover" title="How long since acquired" data-content={{$lengthOwned}}>CLICK FOR TIME LAPSED</a>
与以下 javaScript:
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
有人对 carbon-provided 文本为什么是 missing/truncated 有任何建议吗?
我 运行 Laravel 5.5,PHP 7 XAMPP Windows 10
提前致谢。
您缺少 data-content
值的引号,现在您有:
<a data-content={{$lengthOwned}}>CLICK FOR TIME LAPSED</a>
这将呈现如下内容(将 data-content
的值设置为 4 并添加两个奇怪的属性):
<a data-content=4 months later>CLICK FOR TIME LAPSED</a>
而是将整个值用引号引起来:
<a data-content="{{$lengthOwned}}">CLICK FOR TIME LAPSED</a>