mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-17 04:30:31 +00:00
🔄 Replace ilike/like with whereLike and orWhereLike across views and remove macros for cleaner, driver-agnostic querying
This commit is contained in:
@@ -5,7 +5,6 @@ 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;
|
||||
@@ -40,22 +39,6 @@ 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).
|
||||
|
||||
@@ -26,7 +26,7 @@ class extends Component {
|
||||
'cities' => City::query()
|
||||
->with(['country', 'createdBy'])
|
||||
->when($this->search, fn($query)
|
||||
=> $query->where('name', 'ilike', '%'.$this->search.'%'),
|
||||
=> $query->whereLike('name', '%'.$this->search.'%'),
|
||||
)
|
||||
->whereHas('country', fn($query) => $query->where('countries.code', $this->country))
|
||||
->orderBy('name')
|
||||
|
||||
@@ -29,8 +29,8 @@ class extends Component {
|
||||
])
|
||||
->when($this->search, fn($query)
|
||||
=> $query
|
||||
->where('name', 'ilike', '%'.$this->search.'%')
|
||||
->orWhere('description', 'ilike', '%'.$this->search.'%'),
|
||||
->whereLike('name', '%'.$this->search.'%')
|
||||
->orWhereLike('description', '%'.$this->search.'%'),
|
||||
)
|
||||
->whereHas('courseEvents.venue.city.country', fn($query) => $query->where('countries.code', $this->country))
|
||||
->orderByDesc('has_future_events')
|
||||
|
||||
@@ -40,9 +40,9 @@ class extends Component {
|
||||
fn($query) => $query->where('countries.code', $this->country))
|
||||
->when($this->search, fn($query)
|
||||
=> $query
|
||||
->where('name', 'ilike', '%'.$this->search.'%')
|
||||
->orWhere('description', 'ilike', '%'.$this->search.'%')
|
||||
->orWhere('subtitle', 'ilike', '%'.$this->search.'%'),
|
||||
->whereLike('name', '%'.$this->search.'%')
|
||||
->orWhereLike('description', '%'.$this->search.'%')
|
||||
->orWhereLike('subtitle', '%'.$this->search.'%'),
|
||||
)
|
||||
->orderByDesc('has_future_events')
|
||||
->orderBy('name', 'asc')
|
||||
|
||||
@@ -40,7 +40,7 @@ class extends Component {
|
||||
$query->whereHas('city.country', fn($query) => $query->where('countries.code', $this->country))
|
||||
)
|
||||
->when($this->search, fn($query)
|
||||
=> $query->where('meetups.name', 'ilike', '%'.$this->search.'%'),
|
||||
=> $query->whereLike('meetups.name', '%'.$this->search.'%'),
|
||||
)
|
||||
->orderByDesc('has_future_events')
|
||||
->orderByRaw('next_event_start ASC NULLS LAST')
|
||||
|
||||
@@ -32,7 +32,7 @@ class extends Component {
|
||||
return [
|
||||
'services' => SelfHostedService::query()
|
||||
->with('createdBy')
|
||||
->when($this->search, fn($q) => $q->where('name', 'ilike', '%'.$this->search.'%'))
|
||||
->when($this->search, fn($q) => $q->whereLike('name', '%'.$this->search.'%'))
|
||||
->when($this->typeFilter, fn($q) => $q->where('type', $this->typeFilter))
|
||||
->orderBy('name')
|
||||
->paginate(15),
|
||||
|
||||
@@ -25,7 +25,7 @@ class extends Component {
|
||||
return [
|
||||
'venues' => Venue::with(['city.country', 'createdBy'])
|
||||
->when($this->search, fn($query)
|
||||
=> $query->where('name', 'ilike', '%'.$this->search.'%'),
|
||||
=> $query->whereLike('name', '%'.$this->search.'%'),
|
||||
)
|
||||
->whereHas('city.country', fn($query) => $query->where('countries.code', $this->country))
|
||||
->orderBy('name')
|
||||
|
||||
Reference in New Issue
Block a user