Skip to content

Instantly share code, notes, and snippets.

@waska14
Last active December 28, 2022 01:57
Show Gist options
  • Save waska14/408502aece0898a038662ce8e6f3f41b to your computer and use it in GitHub Desktop.
Save waska14/408502aece0898a038662ce8e6f3f41b to your computer and use it in GitHub Desktop.
Laravel whereNot/orWhereNot in simple trait
<?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