我正在尝试查询我的 NewsItem 表以查找在给定月份/年份撰写的文章。
我正在向 url 传递一个 GET 变量
'/news?filter=true&month=January 2017'
在我的 Controller 中,我正在捕获变量并尝试在我的模态上运行查询
if(Input::get('month')){
$articles = NewsItem::where(DB::raw('created_at'),function($d){
Carbon::parse($d->created_at)->format('F Y') = Input::get('month');
})->get();
};
但是我得到以下错误
FatalErrorException in NewsController.php line 28: Can't use method return value in write context
我想了解更多有关 eloquent 中的函数元素的信息,是否有任何文章可以指导我朝着正确的方向前进?
最佳答案
您的查询需要这样修改
if (Input::get('month')) {
$articles = NewsItem::where('created_at', Carbon::parse(Input::get('month'))->format('F Y'))->get();
};
引用Laravel Where和 Eloquent 101更多信息
关于php - Laravel Eloquent 创建于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41483836/