gpt4 book ai didi

php - Laravel 错误 : Call to a member function format() on string

转载 作者:IT王子 更新时间:2023-10-29 00:04:50 24 4
gpt4 key购买 nike

我正在使用 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')}}

错误:

Call to a member function format() on string (View: D:\wnmp\www\laravel-5-3-dev\resources\views\artiles\index.blade.php)

为什么?

最佳答案

在您的 Article 类中添加以下属性:

/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['expired_at'];

Docs

关于php - Laravel 错误 : Call to a member function format() on string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533377/

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