PHPackages                             lingyun/think-assistor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lingyun/think-assistor

ActiveThink-extend[Utility &amp; Helpers](/categories/utility)

lingyun/think-assistor
======================

ThinkPHP6 composer extension package development assistor. thinkphp6 扩展包开发的一些辅助工具。

v1.0.1(2y ago)025Apache-2.0PHP

Since Sep 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ouyanglingyun/think-assistor)[ Packagist](https://packagist.org/packages/lingyun/think-assistor)[ Docs](https://github.com/ouyanglingyun)[ RSS](/packages/lingyun-think-assistor/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

think-assistor
==============

[](#think-assistor)

thinkphp6 扩展包开发的一些辅助工具。

安装
--

[](#安装)

通过 Composer 包管理器安装 **think-assistor** :

```
composer require lingyun/think-assistor

```

服务辅助器
-----

[](#服务辅助器)

在服务类中获取服务辅助器实例

```
$assistor = $this->app->get('service.assistor');

```

通常扩展包的配置文件发布到应用程序的`config`目录,只需在`composer.json`中加入`extra.think.config`配置,当你的扩展包完成安装或者手动运行`assets:publish`命令时，你的文件将被复制到指定的发布位置。如：

```
"extra": {
    "think": {
        "config": {
            "passport": "src/config/passport.php"
        }
    }
}

```

服务辅助器提供了更多的扩展包资源发布方式

资源
--

[](#资源)

### 配置

[](#配置)

通常，您需要将包的配置文件发布到应用程序的 `config` 目录。 这将允许您的包的用户轻松覆盖您的默认配置选项。 要允许发布配置文件，请从服务提供者的 `boot` 方法中调用服务辅助器的 `publishes` 方法：

```
public function boot()
{
    $assistor = $this->app->get('service.assistor');
    $assistor->publishes([
        __DIR__.'/../config/courier.php' => config_path('courier.php'),
    ]);
}

```

现在，执行 `assets:publish` 命令时，你的文件将被复制到指定的发布位置。

### 数据库迁移

[](#数据库迁移)

如果你的包包含数据库迁移，你可以使用服务辅助器的 `loadMigrationsFrom` 方法告诉 `think-migration` 如何加载它们。 `loadMigrationsFrom` 方法接受包迁移的路径作为其唯一参数：

```
public function boot()
{
    $assistor = $this->app->get('service.assistor');
    $assistor->loadMigrationsFrom(__DIR__.'/../database/migrations');
}

```

一旦您的包的迁移被注册，它们将在执行 `php think migrate:run` 命令时自动运行。 您不需要将它们导出到应用程序的 `database/migrations` 目录。

### 模型工厂

[](#模型工厂)

如果你的包包含模型工厂，你可以使用服务辅助器的 `loadFactoriesFrom` 方法告诉 `think-migration` 加载它们。 `loadFactoriesFrom` 方法接受包迁移的路径作为其唯一参数：

```
public function boot()
{
    $assistor = $this->app->get('service.assistor');
    $assistor->loadFactoriesFrom(__DIR__ . '/../database/factories/');
}

```

可以通过 `think\assistor\model\factories\HasFactory` 特征使用提供给你的模型的静态 `factory` 方法实例化该模型的工厂实例。

```
