Changes
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\StatusScope;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -49,4 +50,9 @@ class News extends Model
|
||||
get: fn($value) => User::find($value) ? User::find($value)->name : '',
|
||||
);
|
||||
}
|
||||
|
||||
public static function boot(){
|
||||
parent::boot();
|
||||
static::addGlobalScope(new StatusScope());
|
||||
}
|
||||
}
|
18
app/Models/Scopes/StatusScope.php
Normal file
18
app/Models/Scopes/StatusScope.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class StatusScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
$builder->where('status',1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user