Friday 13 March 2020

More Eloquent query (where_not_in, where_null)

where_not_in
TableA::whereIn('id',$ids)
      ->whereNotIn('id', function($q){
          $q->select('tabla_id')
            ->from('tableb');
            // more where conditions
      })
      ->get();

https://stackoverflow.com/questions/29643181/eloquent-where-not-in-query

where_null
$query = Model::where('field1', 1)
    ->whereNull('field2')
    ->where(function ($query) {
        $query->where('datefield', '<', $date)
            ->orWhereNull('datefield');
    }
);

No comments:

Post a Comment