-
app/Scopes/AvailableScope.php
Open in GitHubuse Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope; class AvailableScope implements Scope { public function apply(Builder $builder, Model $model) { $builder->available(); } }
-
app/Product.php
Open in GitHubuse App\Scopes\AvailableScope; use Illuminate\Database\Eloquent\Model; class Product extends Model { // protected static function booted() { static::addGlobalScope(new AvailableScope); // } // public function scopeAvailable($query) { return $query->where('status', 'available'); } // }