imalirezapy/laravel-more-command

使用 Artisan CLI 创建仓库、服务、特质和策略

v1.0.0 2023-05-02 09:32 UTC

This package is auto-updated.

Last update: 2024-09-17 12:06:10 UTC


README

issues forks stars GitHub license

Laravel More Command

Laravel More Command 是一组 php artisan 命令。您可以使用它通过 php artisan 命令从命令行创建 仓库、具有接口的仓库、服务、特质、视图(blade 文件),以及 清除日志

[注意:此包也适用于 nWidart/laravel-modules]

安装

使用以下命令通过 composer 需求此包

composer require imalirezapy/laravel-more-command --dev

或者将以下内容添加到 composer.json 的 require-dev 部分,并执行 composer update

"require-dev": {
    "imalirezapy/laravel-more-command": "^1.0.0"
}

发布包配置

 php artisan vendor:publish --provider="imalirezapy\LaravelMoreCommand\LaravelMoreCommandProvider" --tag="config"

要更改默认命名空间 [config/laravel-more-command.php]

<?php
return [
    'repository-namespace' => 'App', // Your Desire Namespace for Repository Classes
    'service-namespace' => 'App', // Your Desire Namespace for Service Classes
];

Artisan 命令列表

  1. 创建仓库
  2. 创建策略
  3. 创建服务
  4. 创建特质
  5. 创建视图
  6. 清除日志

创建仓库

创建仓库类。
php artisan make:repository your-repository-name

示例

php artisan make:repository UserRepository

php artisan make:repository Backend/UserRepository

上述命令将在 App 目录下创建一个 Repositories 目录。

创建具有接口的仓库。
php artisan make:repository your-repository-name -i

示例

php artisan make:repository UserRepository -i

php artisan make:repository Backend/UserRepository -i

这里需要加上额外的 -i 标志。上述命令将在 App 目录下创建一个 Repositories 目录。

nWidart/laravel-modules 模块中

创建仓库类。
php artisan module:make-repository your-repository-name {module-name}

示例

php artisan module:make-repository UserRepository Blog

php artisan module:make-repository Backend/UserRepository Blog

上述命令将在 {Module} 目录下创建一个 Repositories 目录。

创建具有接口的仓库。
php artisan module:make-repository your-repository-name {module-name} -i

示例

php artisan module:make-repository UserRepository -i Blog

php artisan module:make-repository Backend/UserRepository -i Blog

这里需要加上额外的 -i 标志。上述命令将在 {Module} 目录下创建一个 Repositories 目录。

已创建仓库类的示例

<?php

namespace App\Repositories;

class UserRepository
{
    public function __constuct()
    {
        //
    }
}



创建策略

签名: make:strategy {context} {--s|strategy=*} {--i|interface}

创建上下文类。
php artisan make:stratey context-name

示例

php artisan make:strategy PaymentContext

php artisan make:repository Pay/PaymentContext

上述命令将在 app/Services 目录下创建一个 PaymentContext/Pay 目录。

创建策略类。
php artisan make:strategy context-name {--s|strategy=*} (multiple values allowed) 示例

php artisan make:strategy PaymentContext -sOnlinePayment -sOfflinePayment

php artisan make:strategy PaymentContext --strategy=OnlinePayment --strategy=OfflinePayment

创建具有接口的策略。
php artisan make:strategy context-name -i

示例

php artisan make:repository PaymentContext -i

php artisan make:repository Pay/PaymentContext -i

这里需要加上额外的 -i--interface 标志。


创建服务

创建服务类。
php artisan make:service your-service-name

示例

php artisan make:service UserService

php artisan make:service Backend/UserService

上述命令将在 App 目录下创建一个 Services 目录。

nWidart/laravel-modules 模块中

php artisan module:make-service your-service-name {module-name}

示例

php artisan module:make-service UserService

php artisan module:make-service Backend/UserService

上述命令将在 {Module} 目录下创建一个 Services 目录。


创建特质

创建特质。
php artisan make:trait your-trait-name

示例

php artisan make:trait HasAuth

php artisan make:trait Backend/HasAuth

上述命令将在 App 目录下创建一个 Traits 目录。

nWidart/laravel-modules 模块中

php artisan module:make-trait your-trait-name {module-name}

示例

php artisan module:make-trait HasAuth

php artisan module:make-trait Backend/HasAuth

上述命令将在 {Module} 目录下创建一个 Traits 目录。


创建视图

创建视图。
php artisan make:view your-view-file-name

示例

php artisan make:view index

php artisan make:view user/index

上述命令将在 /resource/views/ 目录下创建一个 blade 文件。

nWidart/laravel-modules 模块中

php artisan module:make-view your-view-file-name {module-name}

示例

php artisan module:make-view index

php artisan module:make-view user/index

上述命令将在 {Module}/Resources/views/ 目录下创建一个 blade 文件。


清除日志

php artisan log:clear

上述操作将删除 /storage/logs/ 目录下的所有旧日志数据。

许可证

MIT 许可证(MIT)。更多信息请参阅 许可证