Die*_*des 2 php laravel laravel-5.1
我有我的文章资源控制器,像这样:
public function articles()
{
$articles = Article::OrderBy('id','DESC')->paginate(3);
return view('blog', compact('articles'));
}
Run Code Online (Sandbox Code Playgroud)
我想将两个变量传递给我的视图,如下所示:
$day = day of created article
$month = month of created article
return view('blog', compact('articles','day','month'));
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何从数据库中获取这些数据,我可以像这样得到创建日期:
$article->created_at
Run Code Online (Sandbox Code Playgroud)
我怎样才能将日期和月份传递给我的观点?
默认情况下,created_at转换为Carbon实例(引用).因此,您可以直接从酒店获取日期和月份属性!
@foreach($articles as $article)
{{ $article->created_at->day }}
{{ $article->created_at->month }}
@endforeach
Run Code Online (Sandbox Code Playgroud)