Fixed: Dont search for anything if search is empty

This commit is contained in:
philipp lang 2021-07-15 20:59:06 +02:00
parent 7f7b652e69
commit be6bd73762
1 changed files with 3 additions and 2 deletions

View File

@ -14,7 +14,7 @@ use App\Subactivity;
use Zoomyboy\LaravelNami\NamiUser; use Zoomyboy\LaravelNami\NamiUser;
use App\Payment\Subscription; use App\Payment\Subscription;
use App\Payment\Payment; use App\Payment\Payment;
use Illuminate\Database\Query\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use App\Confession; use App\Confession;
@ -42,7 +42,8 @@ class Member extends Model
'is_confirmed' => 'boolean', 'is_confirmed' => 'boolean',
]; ];
public function scopeSearch(Builder $q, string $text): Builder { public function scopeSearch(Builder $q, ?string $text): Builder {
if (is_null($text)) { return $q; }
return $q->where('firstname', 'LIKE', '%'.$text.'%') return $q->where('firstname', 'LIKE', '%'.$text.'%')
->orWhere('lastname', 'LIKE', '%'.$text.'%') ->orWhere('lastname', 'LIKE', '%'.$text.'%')
->orWhere('address', 'LIKE', '%'.$text.'%') ->orWhere('address', 'LIKE', '%'.$text.'%')