PHP laravel query


PHP laravel query

如何查询上次捐款超过90天的所有用户。 这是我的查询,但是当它执行时,我收到一个错误未知列。

      $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' )
->where('lastDonation', '<', Carbon::now()->subDays(90))
->whereNotIn('username', [$value ])
->get();
您可以使用

TIMESTAMPDIFF mysql 函数来计算两个日期时间之间的差异。

为此,您需要使用 whereRaw 添加一个子句

$value = Session::get('key');
$dateToday = new DateTime();
$data = Users::where('userType', '=', 'user')
          ->whereRaw('TIMESTAMPDIFF(DAY, lastDonation, NOW()) > 90')
          ->whereNotIn('username', [$value])
          ->get();