Laravel错误:在字符串上调用成员函数format() [英] Laravel error: Call to a member function format() on string
本文介绍了Laravel错误:在字符串上调用成员函数format()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel 5.3
.
I am using Laravel 5.3
.
表articles
中有一个字段expired_at
:
public function store(Request $request)
{
$data=[
'expired_at'=>Carbon::now()->addDays(30)->endOfDay()
];
$article=Article::create(array_merge($request->all(),$data));
return redirect('/artilces');
}
视图:
{{$article->expired_at->format('Y-m-d')}}
错误:
在字符串上调用成员函数format()(视图:D:\ wnmp \ www \ laravel-5-3-dev \ resources \ views \ artiles \ index.blade.php)
Call to a member function format() on string (View: D:\wnmp\www\laravel-5-3-dev\resources\views\artiles\index.blade.php)
为什么?
推荐答案
在您的Article
类中添加以下属性:
In your Article
class add following property:
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['expired_at'];
这篇关于Laravel错误:在字符串上调用成员函数format()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文