我正在尝试在laravel5.2中使用德语的Carbon的diffForHumans()显示created_at属性。created_at在数据库中存储为:2017-03-2917:31:52模型protected$dates=['created_at','updated_at'];publicstaticfunctiongetCreatedAtAttribute($value){Carbon::setLocale('de');returnCarbon::parse($value,'Europe/Berlin')->diffForHumans();}dd($value);返回"2017
根据手册:http://carbon.nesbot.com/docs/#api-humandiff获取一个agoWhencomparingavalueinthepasttodefaultnow但无论我做什么,我都无法获取ago返回$datetime->diffForHumans(Carbon::now())之前的结果,而returnCarbon::now()->diffForHumans($datetime);之后的结果,但是你可以清楚地看到我上面的两个代码片段比较了past($datetime)和现在的默认值(Carbon::now())所以我不明白为什么我不能得到以前?希望有人能帮
在我的表中设置一个时间戳字段,以便在字段中创建和更新。然后在我的模型中我这样做:protected$dates=['created_at','updated_at'];但是调用日期时:$p->created_at->diffForHumans()我明白了CalltoamemberfunctiondiffForHumans()onstring我很确定这应该有效。我之前在不同型号等上多次使用相同的方法,但这行不通。 最佳答案 默认情况下,Eloquent会将created_at和updated_at列转换为Carbon的实例,它提供了各
我想使用Carbon显示一个日期的天数和小时数,目前我得到了下面的代码。Carbon::parse("2017-03-0717:46:50")->diffForHumans()输出:6daysfromnow我希望它输出这样的东西:6daysand12hoursfromnow我该怎么做? 最佳答案 您可以像这样指定详细程度:Carbon::parse("2017-03-0717:46:50")->diffForHumans(['parts'=>6]);您可以使用1到6之间的值。(Doc)
为什么当我使用查询生成器而不是函数diffForHumans()时出现错误,但是如果我使用ELoquentROM但没有错误有办法克服它吗?(我该如何解决)谢谢diffForHumans()这是ArticlesController.phpnamespaceApp\Http\Controllers;useIlluminate\Http\Request;useApp\Article;useCarbon\Carbon;useAuth;useDB;classArticlesControllerextendsController{publicfunctionindex(){$articles=DB