mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-17 16:40:31 +00:00
✨ 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:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user