Skip to content

Commit

Permalink
Bugfix: Scopes OltherThan, YoungerThan on couple
Browse files Browse the repository at this point in the history
  • Loading branch information
MGeurts committed Oct 19, 2024
1 parent f0da3ea commit 3ca75fb
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions app/Models/Couple.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Spatie\Activitylog\LogOptions;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Spatie\Activitylog\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Couple extends Model
{
Expand Down Expand Up @@ -71,24 +72,24 @@ protected static function booted(): void
/* -------------------------------------------------------------------------------------------- */
// Scopes (local)
/* -------------------------------------------------------------------------------------------- */
public function scopeOlderThan(Builder $query, ?string $date_start): void
public function scopeOlderThan(Builder $query, ?string $birth_year): void
{
if (empty($date_start)) {
if (empty($birth_year)) {
return;
} else {
$query->where(function ($q) use ($date_start) {
$q->whereNull('date_start')->orWhere('date_start', '<=', $date_start);
$query->where(function ($q) use ($birth_year) {
$q->whereNull('date_start')->orWhere(DB::raw('YEAR(date_start)'), '<=', $birth_year);
});
}
}

public function scopeYoungerThan(Builder $query, ?string $date_start): void
public function scopeYoungerThan(Builder $query, ?string $birth_year): void
{
if (empty($date_start)) {
if (empty($birth_year)) {
return;
} else {
$query->where(function ($q) use ($date_start) {
$q->whereNull('date_start')->orWhere('date_start', '>=', $date_start);
$query->where(function ($q) use ($birth_year) {
$q->whereNull('date_start')->orWhere(DB::raw('YEAR(date_start)'), '>=', $birth_year);
});
}
}
Expand Down

0 comments on commit 3ca75fb

Please sign in to comment.