Example of Local scopes in Kovah/LinkAce

File app/Models/Link.php (link to Github)
use Illuminate\Database\Eloquent\Model;

class Link extends Model
{
    public function scopeByUser(Builder $query, int $userId): Builder
    {
        return $query->where('user_id', $userId);
    }
}
File app/Http/Controllers/App/DashboardController.php (link to Github)
use App\Http\Controllers\Controller;
use App\Models\Link;
use App\Models\LinkList;
use App\Models\Note;
use App\Models\Tag;
use Illuminate\Contracts\View\View;

class DashboardController extends Controller
{
    public function index(): View
    {
        $recentLinks = Link::byUser(auth()->user()->id)
            ->latest()
            ->limit(5)
            ->get();

        $recentTags = Tag::byUser(auth()->user()->id)
            ->latest()
            ->limit(25)
            ->get();

        $recentLists = LinkList::byUser(auth()->user()->id)
            ->latest()
            ->limit(15)
            ->get();

        $brokenLinks = Link::byUser(auth()->user()->id)
            ->where('status', '>', 1)
            ->count();

        return view('dashboard', [
            'recent_links' => $recentLinks,
            'recent_tags' => $recentTags,
            'recent_lists' => $recentLists,
        ]);
    }
}

Additional resources on local scopes: