承接 curly-deni/laravel-scopes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

curly-deni/laravel-scopes

Composer 安装命令:

composer require curly-deni/laravel-scopes

包简介

A set of reusable Eloquent global scopes for controlling model visibility based on user ownership and public/private status, designed for seamless integration with Laravel authorization policies.

README 文档

README

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Laravel Scopes provides a set of reusable Eloquent global scopes to control model visibility based on user ownership and public/private status.
It is designed for easy integration with Laravel's authorization policies.

Features

  • ✅ Simple and lightweight integration
  • ✅ Reusable Eloquent scopes for ownership and visibility
  • ✅ Works seamlessly with Laravel Policies
  • ✅ No manual query building required
  • ✅ Clean separation of concerns between data and authorization

Installation

Install the package via Composer:

composer require curly-deni/laravel-scopes

Usage

All traits are located under the Aesis\Scopes\Traits namespace.

Available traits

  • HasOwnershipScope — restricts access to models owned by the current user (user_id field required).
  • HasPublicScope — restricts access to public models (public field required).
  • HasPrivateScope — restricts access to private models (private field required).
  • HasSelfScope — allows users to see their own models in addition to public/private ones (user_id field required).

Usage Scenarios

1. Restrict models to the owner only

Use HasOwnershipScope when users should only see their own models.

use Aesis\Scopes\Traits\HasOwnershipScope;

class Post extends Model
{
    use HasOwnershipScope;
}

2. Restrict models based on public/private status

Use HasPublicScope or HasPrivateScope to filter models by their visibility flag.
Optionally, add HasSelfScope to also allow users to see their own models.

use Aesis\Scopes\Traits\HasPublicScope;
use Aesis\Scopes\Traits\HasSelfScope;

class Post extends Model
{
    use HasPublicScope, HasSelfScope;
}

Trait Selection Guide

Use Case Required Traits
Users should see only their own models HasOwnershipScope
Users should see only public models HasPublicScope
Users should see only private models HasPrivateScope
Users should see public models and their own private models HasPublicScope + HasSelfScope
Users should see private models and their own private models HasPrivateScope + HasSelfScope

Database Requirements

Trait Required Field
HasPublicScope public
HasPrivateScope private
HasOwnershipScope user_id
HasSelfScope user_id

Policy Requirements

When using scopes, you should define the following permissions in your model policies:

Method Purpose
viewPrivate(User $user) Allows a user to view private models (e.g., admins or users with special roles).
viewForeign(User $user) Allows a user to view other users' models (in addition to their own, if HasSelfScope is used).

Example policy:

class PostPolicy
{
    public function viewPrivate(User $user): bool
    {
        // Allow access to private models for admins
        return $user->is_admin;
    }

    public function viewForeign(User $user): bool
    {
        // Allow users to view models owned by others
        return $user->can('view-others-posts');
    }
}

Restrictions

  • HasOwnershipScope cannot be combined with any other traits.
  • HasPublicScope and HasPrivateScope cannot be used together.
  • HasSelfScope requires either HasPublicScope or HasPrivateScope.

Credits

License

The MIT License (MIT).
Please see the LICENSE.md file for more information.

Summary

Laravel Scopes help you automatically filter models by ownership or visibility status without writing repetitive query logic.
Combined with authorization policies, it provides flexible and secure access control at the Eloquent level.

curly-deni/laravel-scopes 适用场景与选型建议

curly-deni/laravel-scopes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「authorization」 「visibility」 「laravel」 「eloquent」 「laravel package」 「scopes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 curly-deni/laravel-scopes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 curly-deni/laravel-scopes 我们能提供哪些服务?
定制开发 / 二次开发

基于 curly-deni/laravel-scopes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-26