Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save me7media/1a7bc6fc5f8e9ac79c78e00980c3d207 to your computer and use it in GitHub Desktop.
Save me7media/1a7bc6fc5f8e9ac79c78e00980c3d207 to your computer and use it in GitHub Desktop.
Laravel WhereNotIn takes null. WhereIn with NULL.
//Client model
private $notSaleSections = ['ТПМ-УПП', 'ТПМ-МДФ'];
public function saleParams()
{
return $this->hasMany(ClientParameter::class, 'customer', 'id')
->whereHas('param', function ($q) {
$q->where('section', null);
foreach ($this->notSaleSections as $s){
$q->orWhere('section', '!=', $s);
}
});
}
//ClientParameter model relation to self? you can use other relation
public function param(){
return $this->hasOne($this, 'id', 'id');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment