mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
add published scope
This commit is contained in:
parent
7ee542856d
commit
f04fbab5c6
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Models\Scopes\DisabledScope;
|
use App\Models\Scopes\DisabledScope;
|
||||||
|
use App\Models\Scopes\PublishedScope;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -26,6 +27,8 @@ class Mod extends Model
|
|||||||
{
|
{
|
||||||
// Apply the global scope to exclude disabled mods.
|
// Apply the global scope to exclude disabled mods.
|
||||||
static::addGlobalScope(new DisabledScope);
|
static::addGlobalScope(new DisabledScope);
|
||||||
|
// Apply the global scope to exclude non-published mods.
|
||||||
|
static::addGlobalScope(new PublishedScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Models\Scopes\DisabledScope;
|
use App\Models\Scopes\DisabledScope;
|
||||||
|
use App\Models\Scopes\PublishedScope;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -15,6 +16,7 @@ class ModVersion extends Model
|
|||||||
protected static function booted(): void
|
protected static function booted(): void
|
||||||
{
|
{
|
||||||
static::addGlobalScope(new DisabledScope);
|
static::addGlobalScope(new DisabledScope);
|
||||||
|
static::addGlobalScope(new PublishedScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mod(): BelongsTo
|
public function mod(): BelongsTo
|
||||||
|
19
app/Models/Scopes/PublishedScope.php
Normal file
19
app/Models/Scopes/PublishedScope.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Scopes;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Scope;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class PublishedScope implements Scope
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Apply the scope to a given Eloquent query builder.
|
||||||
|
*/
|
||||||
|
public function apply(Builder $builder, Model $model): void
|
||||||
|
{
|
||||||
|
$builder->where($model->getTable().'.published_at', "<=", now());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user