Add whereLike and orWhereLike macros for driver-agnostic case-insensitive searches

- 🔄 Replace `ilike`/`like` conditions with `whereLike` in API controllers and search tools for consistency.
- 🚀 Enhance query usability by ensuring cross-database compatibility (PostgreSQL and SQLite).
This commit is contained in:
HolgerHatGarKeineNode
2026-06-14 01:32:03 +02:00
parent 6239842b15
commit f93190f029
14 changed files with 42 additions and 28 deletions
+17
View File
@@ -5,6 +5,7 @@ namespace App\Providers;
use App\Support\Carbon;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Events\DiagnosingHealth;
use Illuminate\Http\Request;
@@ -39,6 +40,22 @@ class AppServiceProvider extends ServiceProvider
{
$this->configureRateLimiting();
// Case-insensitive Teilstring-Suche DB-portabel halten: PostgreSQL
// kennt `ilike`, SQLite (lokales Dev / Tests) nicht — dort liefert ein
// hartkodiertes `ilike` einen Syntaxfehler. Auf SQLite ist `like`
// ohnehin case-insensitiv (ASCII), sodass das Produktionsverhalten
// (PostgreSQL/ilike) unverändert bleibt. Verwendung in den API-
// Controllern: ->whereLike('name', "%{$search}%").
Builder::macro('whereLike', function (string $column, string $value, string $boolean = 'and') {
$operator = $this->getConnection()->getDriverName() === 'pgsql' ? 'ilike' : 'like';
return $this->where($column, $operator, $value, $boolean);
});
Builder::macro('orWhereLike', function (string $column, string $value) {
return $this->whereLike($column, $value, 'or');
});
Gate::define('viewApiDocs', fn (?Authenticatable $user = null): bool => true);
// OAuth-2.1-Flow des MCP-Servers (Claude.ai Web-Connector).