syntech/globalscopes
最新稳定版本:2.0.1
Composer 安装命令:
composer require syntech/globalscopes
包简介
A Laravel package to add general model scopes to all models
README 文档
README
A Laravel package for adding global model scopes and attributes without modifying individual models.
Installation
You can install the package via Composer:
composer require syntech/globalscopes
Configuration
Publish the configuration file:
php artisan vendor:publish --provider="Syntech\GlobalScopes\GlobalScopesServiceProvider"
This will create a globalscopes.php configuration file in the config directory of your Laravel application.
Example Configuration
return [ /* |-------------------------------------------------------------------------- | Global Query Methods |-------------------------------------------------------------------------- | | Define any global query methods that should be available across all | Eloquent models. These methods can be used to add commonly used query | functionality to all models. | | Example: | 'active' => function () { | return $this->where('status', 1); | }, | */ 'methods' => [ 'active' => function () { return $this->where('status', 1); }, 'someMore' => function () { // add more ... } ], ];
Usage
Adding Global Scopes
Once configured, the global scopes will automatically be applied to all Eloquent models. Adding Global Attributes
Global attributes can be accessed as if they are defined directly on the model:
$customers = Customer::active()->get();
return $customers; // Uses the global attribute logic
统计信息
- 总下载量: 300
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-03