Laravel 5 仓库生成器。

1.0.5 2016-09-19 07:16 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:47:48 UTC


README

Laravel 5 仓库生成器。

用法

步骤 1: 通过 Composer 安装

composer require laravel_tools_dev/repoist --dev

步骤 2: 添加服务提供者

您只需将这些生成器用于本地开发,因此您不想更新生产环境中的 providers 数组在 config/app.php 中。相反,在 app/Providers/AppServiceProvider.php 中添加提供者,如下所示

public function register()
{
	if ($this->app->isLocal()) {
		$this->app->register('Kurt\Repoist\RepoistServiceProvider');
	}
}

步骤 3: 发布并编辑配置

从控制台运行 php artisan vendor:publish 以根据您的需求配置 Repoist。

步骤 4: 运行 Artisan!

您已设置完毕。从控制台运行 php artisan,您将在 make:repository 命名空间部分看到新的命令。

示例

无架构的仓库

php artisan make:repository Task

将输出

  • app/Interfaces/Task/TaskRepositoryInterface.php (契约)
  • app/Repositories/Task/TaskRepositoryEloquent.php

有架构的仓库

php artisan make:repository Task -m

将输出

  • app/Interfaces/Task/TaskRepositoryInterface.php (契约)
  • app/Repositories/Task/TaskRepositoryEloquent.php
  • app/Models/TaskEloquent.php

配置

如果您在这里无法从 artisan 发布 config/repoist.php,您可以复制并使用它。

<?php

return [

    /**
     * Default paths.
     * In this case:
     *      app/Interfaces
     *      app/Repositories
     *      app/Models
     */
    'paths' => [
            'contract' => 'app/Interfaces',
            'eloquent' => 'app/Repositories',
            'model' => 'app/Models',
    ],
    /**
     * Configure the naming convention you wish for your repositories.
     *
     * Example: php artisan make:repository Users
     *      - Contract: UsersRepository
     *      - Eloquent: EloquentUsersRepository
     *      - Model   : UsersEloquent
     */
    'fileNames' => [

        'contract' => '{name}RepositoryInterface',
        'eloquent' => '{name}RepositoryEloquent',
        'model' => '{name}Eloquent',

    ],

];