我的问题是,我只想created_at按年和月从属性中获取数据库表中的数据。我试过的代码是:
created_at
$post= Mjblog::select(DB::raw('YEAR(created_at) year, MONTH(created_at) month')); $posts_by_y_m = $post->where('created_at',$post)->get();
查询构建器中有可用的日期帮助器:
$post = Mjblog::whereYear('created_at', '=', $year) ->whereMonth('created_at', '=', $month) ->get();