我正在使用Laravel 5.3

expired_at中有一个字段articles:

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')}}

错误:



为什么?

最佳答案

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/

10-13 07:49