Skip to content

Commit

Permalink
[Update] Route Binding
Browse files Browse the repository at this point in the history
- Added explicit `withoutGlobalScopes` as it works better
  • Loading branch information
kiritokatklian committed Jul 21, 2024
1 parent 15d6aa4 commit 711c150
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Models/Anime.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public function languages(): HasManyThrough
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class, IgnoreListScope::class]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Episode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Enums\MediaCollection;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\Actionable;
use App\Traits\Model\HasComments;
Expand Down Expand Up @@ -399,7 +400,7 @@ public function videos(): MorphMany
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class]);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Enums\DayOfWeek;
use App\Enums\MediaCollection;
use App\Enums\SeasonOfYear;
use App\Scopes\IgnoreListScope;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\Actionable;
use App\Traits\Model\Favorable;
Expand Down Expand Up @@ -620,7 +622,7 @@ public function toSearchableArray(): array
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class, IgnoreListScope::class]);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions app/Models/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Models;

use App\Enums\MediaCollection;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\HasSlug;
use App\Traits\Model\TvRated;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand Down Expand Up @@ -117,12 +119,12 @@ public function toSearchableArray(): array
* @param Model|\Illuminate\Database\Eloquent\Relations\Relation $query
* @param mixed $value
* @param string|null $field
* @return \Illuminate\Contracts\Database\Eloquent\Builder
* @return Builder
*/
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
public function resolveRouteBindingQuery($query, $value, $field = null): Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class]);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Manga.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Enums\DayOfWeek;
use App\Enums\MediaCollection;
use App\Enums\SeasonOfYear;
use App\Scopes\IgnoreListScope;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\Actionable;
use App\Traits\Model\Favorable;
Expand Down Expand Up @@ -679,7 +681,7 @@ public function toSearchableArray(): array
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class, IgnoreListScope::class]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Models/MediaRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Scopes\TvRatingScope;
use App\Traits\Model\MorphTvRated;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -53,6 +54,6 @@ public function user(): BelongsTo
public function resolveRouteBindingQuery($query, $value, $field = null): Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class]);
}
}
3 changes: 2 additions & 1 deletion app/Models/Season.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Enums\MediaCollection;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\HasViews;
use App\Traits\Model\TvRated;
Expand Down Expand Up @@ -129,7 +130,7 @@ public function tv_rating(): BelongsTo
public function resolveRouteBindingQuery($query, $value, $field = null): Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Studio.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Casts\AsArrayObject;
use App\Enums\MediaCollection;
use App\Enums\StudioType;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\HasMediaRatings;
use App\Traits\Model\HasMediaStat;
Expand Down Expand Up @@ -293,7 +294,7 @@ public function tv_rating(): BelongsTo
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class]);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Models/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Enums\MediaCollection;
use App\Scopes\TvRatingScope;
use App\Traits\InteractsWithMediaExtension;
use App\Traits\Model\HasSlug;
use App\Traits\Model\TvRated;
Expand Down Expand Up @@ -134,7 +135,7 @@ public function toSearchableArray(): array
public function resolveRouteBindingQuery($query, $value, $field = null): \Illuminate\Contracts\Database\Eloquent\Builder
{
return parent::resolveRouteBindingQuery($query, $value, $field)
->withoutTvRatings();
->withoutGlobalScopes([TvRatingScope::class]);
}

/**
Expand Down

0 comments on commit 711c150

Please sign in to comment.