The data table has a expired_at
field. The data is like this:
public function store(Request $request)
{
$data=[
'expired_at'=>Carbon::now()->addDays($publishing_days)->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)
what happened?
This error message itself has told you that expire_at is a string, and there is no format method for strings in PHP (actually there is no method, because string is not an object in PHP)
First expired_at needs to be of type
timestamp
或者datetime
in the databaseSecondly, add this field to $dates
Then you can call it as Carbon