Fresh code drop

Apply a global query scope

PHP

Original 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

Turn your code into a post.Five templates are free—no account needed.

Remix this snap