Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel error: Call to a member function format() on string

Tags:

php

laravel

I am using Laravel 5.3.

There is a field expired_at in table 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'); } 

view:

{{$article->expired_at->format('Y-m-d')}} 

error:

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

Why is it?

like image 746
zwl1619 Avatar asked Nov 10 '16 17:11

zwl1619


1 Answers

In your Article class add following property:

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

Docs

like image 152
Amit Gupta Avatar answered Oct 20 '22 01:10

Amit Gupta