-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DB): Macros for null or empty dealings
- Loading branch information
Showing
3 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace CustomD\LaravelHelpers\Database\Query\Mixins; | ||
|
||
use Illuminate\Database\Query\Builder; | ||
|
||
/** @mixin \Illuminate\Database\Query\Builder */ | ||
|
||
class NullOrEmptyMixin | ||
{ | ||
|
||
public function whereNullOrEmpty() | ||
{ | ||
return function (string $column) { | ||
/** @var \Illuminate\Database\Query\Builder $this */ | ||
return $this->where(fn (Builder $builder) => $builder->where($column, '=', '')->orWhereNull($column)); | ||
}; | ||
} | ||
|
||
public function orWhereNullOrEmpty() | ||
{ | ||
return function (string $column) { | ||
/** @var \Illuminate\Database\Query\Builder $this */ | ||
return $this->orWhere(fn (Builder $builder) => $builder->where($column, '=', '')->orWhereNull($column)); | ||
}; | ||
} | ||
|
||
|
||
public function whereNotNullOrEmpty() | ||
{ | ||
return function (string $column) { | ||
/** @var \Illuminate\Database\Query\Builder $this */ | ||
return $this->where(fn(Builder $builder) => $builder->where($column, '!=', '')->whereNotNull($column)); | ||
}; | ||
} | ||
|
||
public function orWhereNotNullOrEmpty() | ||
{ | ||
return function (string $column) { | ||
/** @var \Illuminate\Database\Query\Builder $this */ | ||
return $this->orWhere(fn(Builder $builder) => $builder->where($column, '!=', '')->orWhereNotNull($column)); | ||
}; | ||
} | ||
} |
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