Last active
December 28, 2022 01:57
-
-
Save waska14/408502aece0898a038662ce8e6f3f41b to your computer and use it in GitHub Desktop.
Laravel whereNot/orWhereNot in simple trait
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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