按月和年创建图像相册组并显示相册的第一张图像
Create Image Album Group By Month and Year and Show First Image of the Album
我正在创建按日期分组的相册,
在我的博客应用程序中,每个 post 都有一张特色图片,我想创建一个按年和月分组的图片相册,并将相册的第一张图片显示为相册封面,我已经按日期对我的 post 进行了分组,但问题是我无法将专辑的第一张图片作为专辑的封面
这是我按日期 post 按博客
分组的方式
$postdates = App\Post::select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
->groupBy('year')
->groupBy('month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->limit(12)
->get();
?>
这是我获取图像的方式
问题是我想在这里
@foreach($postdates as $postdate)
<li><a href="#"><img src="{{asset('images/'. $postdate->featured_image)}}" alt=""></a></li>
@endforeach
"featured_image" 是图像名称的 table 列。
已经收到了,谢谢
$postdates = App\Post::select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count, MIN(featured_image) as image'))
->groupBy('year')
->groupBy('month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->limit(12)
->get();
我正在创建按日期分组的相册,
在我的博客应用程序中,每个 post 都有一张特色图片,我想创建一个按年和月分组的图片相册,并将相册的第一张图片显示为相册封面,我已经按日期对我的 post 进行了分组,但问题是我无法将专辑的第一张图片作为专辑的封面
这是我按日期 post 按博客
分组的方式$postdates = App\Post::select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
->groupBy('year')
->groupBy('month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->limit(12)
->get();
?>
这是我获取图像的方式 问题是我想在这里
@foreach($postdates as $postdate)
<li><a href="#"><img src="{{asset('images/'. $postdate->featured_image)}}" alt=""></a></li>
@endforeach
"featured_image" 是图像名称的 table 列。
已经收到了,谢谢
$postdates = App\Post::select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count, MIN(featured_image) as image'))
->groupBy('year')
->groupBy('month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->limit(12)
->get();