我正在尝试根据过去的日期获取作家的消息。到目前为止,我已经编写了函数:
public static function getNewsByAuthorByDate($id, $year, $limit = 1){
return User::where('id', $id)->has('news')
->with(['news' => function($q) use(&$limit, &$year) {
$q->where('created_at', 'like', '%' . $year . '%')->latest()->limit($limit);
}])
->first();
}
但是news[]
是空的。是否可以根据日期获取作家新闻,还是我必须尝试其他方式?