Dinesh Uprety
@dineshuprety ·
Public
Apply a global query scope
PHPOriginal CodeSnap example inspired by Laravel News. Source: https://laravel-news.com/eloquent-tips-tricks
PHP
CodeSnap // free canvas
Apply a global query scope
<?php
protected static function booted(): void
{
static::addGlobalScope('active', fn ($query) =>
$query->where('is_active', true)
);
}
// Further reading: https://laravel-news.com/eloquent-tips-tricks