PHP laravel查询
如何查询最近一次捐款超过90天的所有用户。这是我的查询,但在执行时,我得到一个错误未知列PHP laravel查询,php,database,laravel,Php,Database,Laravel,如何查询最近一次捐款超过90天的所有用户。这是我的查询,但在执行时,我得到一个错误未知列 $value = Session::get('key'); $dateToday = new DateTime(); $data = Users::where('userType','=', 'user' ) ->where($dateToday->format('m/d/Y') - 'lastDonation', '=', 1
$value = Session::get('key');
$dateToday = new DateTime();
$data = Users::where('userType','=', 'user' )
->where($dateToday->format('m/d/Y') - 'lastDonation', '=', 1)
->whereNotIn('username', [$value ])
->get();
$data=Users::where('userType'、'='、'user')
->其中('last捐赠','您可以使用mysql函数来计算两个日期时间之间的差异
为此,您需要使用whereRaw
$value = Session::get('key');
$dateToday = new DateTime();
$data = Users::where('userType', '=', 'user')
->whereRaw('TIMESTAMPDIFF(DAY, lastDonation, NOW()) > 90')
->whereNotIn('username', [$value])
->get();
为了节省时间,您可以使用dd($data->toSql())
检查代码,并删除->get()
以重新检查查询生成器
$value = Session::get('key');
$dateToday = new DateTime();
$data = Users::where('userType', '=', 'user')
->whereRaw('TIMESTAMPDIFF(DAY, lastDonation, NOW()) > 90')
->whereNotIn('username', [$value])
->get();