简体   繁体   中英

Laravel: Unable to use Carbon diffForHumans in blades

调用字符串上的成员函数 diffForHumans() .. 我实际上在做的是在刀片中获取的日期上调用 diffForHumans。

<span>{{$data['date']->diffForHumans()}}</span>
{{ \Carbon\Carbon::parse($data['date'])->diffForHumans() }}

As already mentioned your $data['date'] probably isn't an instance of Carbon already and therefore needs to be parsed. The above will resolve carbon, parse it and get the diff.

<span>{{ \\Carbon\\Carbon::parse($data->created_at)->diffForHumans() }}</span>
the $data->iffForHumans(); method only works in .PHP file if you add use Carbon\\Carbon;
BUT in .blade you must write full reference of carbon and parse if to string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM