Skip to content

Instantly share code, notes, and snippets.

@neutronstein
Forked from waska14/HasWhereNotTrait.php
Created July 31, 2020 21:17
Show Gist options
  • Save neutronstein/d5fc8c3be0f057fd345897a1b6a3d244 to your computer and use it in GitHub Desktop.
Save neutronstein/d5fc8c3be0f057fd345897a1b6a3d244 to your computer and use it in GitHub Desktop.
app/Traits/HasWhereNotTrait.php
<?php
namespace App\Traits;
use Closure;
use Illuminate\Database\Eloquent\Builder;
trait HasWhereNotTrait
{
/**
* @param Builder $query
* @param string|Closure $column
* @param mixed $value
*/
public function scopeWhereNot($query, $column, $value = null)
{
$query->where($column, $value, null, 'and not');
}
/**
* @param Builder $query
* @param string|Closure $column
* @param mixed $value
*/
public function scopeOrWhereNot($query, $column, $value = null)
{
$query->where($column, $value, null, 'or not');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment