mingyukim/more-command

添加 artisan 命令 What I Want!

0.2.9 2023-08-25 07:11 UTC

This package is auto-updated.

Last update: 2024-09-25 09:38:03 UTC


README

artisan make 中没有,但可以轻松创建常用的模式和类命令的库

安装方法

使用以下命令通过 composer 安装包

composer require mingyukim/more-command

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

"require": {
      "mingyukim/more-command": "*"
}

发布包设置文件

 php artisan vendor:publish --provider="MingyuKim\MoreCommand\MoreCommandProvider" --tag="config"

更改基本命名空间 [config/more-command.php]

<?php
return [
    'repository-namespace' => 'App', // 저장소 클래스에 대한 원하는 네임스페이스
    'trait-namespace' => 'App', // Traits에 대한 원하는 네임스페이스
    'service-namespace' => 'App', // 서비스에 대한 원하는 네임스페이스   
    'view-root-path' => 'resources' // Blade 템플릿 생성 장소. view-root-path/views/ 하위에 생성됨.
];

创建所有 Repository

参考 App/Models 文件夹创建 repository Class。
php artisan make:repositories {--print}

示例

php artisan make:repositories

逐个创建 Repository

创建一个 repository Class。
php artisan make:repository {--print} {repositoryName}

示例

php artisan make:repository TestRepository

结果

<?php

namespace App\Repositories;

use App\Models\Test;
use App\Repositories\BaseTemplate\BaseRepository;
use App\Repositories\BaseTemplate\RepositoryInterface;

class TestRepository extends BaseRepository implements RepositoryInterface
{
    public function __construct(Test $model = null)
    {
        if($model == null) {
            $model = new Test();
        }
        parent::__construct($model);
    }

    public function findById($id, array $columns = ['*'], array $relations = [])
    {
        return parent::findById($id, $columns, $relations); // TODO: Change the autogenerated stub
    }

    public function all(array $columns = ['*'], array $relations = [])
    {
        return parent::all($columns, $relations); // TODO: Change the autogenerated stub
    }

    public function firstOrNew(array $attributes = [], array $values = [])
    {
        return parent::firstOrNew($attributes, $values); // TODO: Change the autogenerated stub
    }

    public function firstOrCreate(array $attributes = [], array $values = [])
    {
        return parent::firstOrCreate($attributes, $values); // TODO: Change the autogenerated stub
    }

    public function insert($arrItems)
    {
        return parent::insert($arrItems); // TODO: Change the autogenerated stub
    }

    public function create(array $attributes)
    {
        return parent::create($attributes); // TODO: Change the autogenerated stub
    }

    public function update($id, array $attributes)
    {
        return parent::update($id, $attributes); // TODO: Change the autogenerated stub
    }

    public function updateOrCreate(array $attributes, array $values = [])
    {
        return parent::updateOrCreate($attributes, $values); // TODO: Change the autogenerated stub
    }

    public function delete($ids)
    {
        return parent::delete($ids); // TODO: Change the autogenerated stub
    }

}

逐个创建 Trait

创建一个 Trait File。
php artisan make:trait {--print} {triatName} {--s}

示例

php artisan make:trait TestTrait
php artisan make:trait TestSingleTonTrait --s // 싱글톤 패턴

结果

<?php

namespace App\Traits;

trait TestTrait
{

}
<?php

namespace App\Traits;

trait TestSingleTonTrait
{
    private static $instanse = null;

    /**
     *
     * @return self
     */
    static function getInstance()
    {
        if (self::$instanse == null) {
            self::$instanse = new self;
        }

        return self::$instanse;
    }
}

逐个创建 Service

创建一个 Service Class。
php artisan make:service {--print} {serviceName}

示例

php artisan make:service TestService

结果

<?php

namespace App\Services;

use App\Repositories\TestRepository;

class TestService
{
    protected $repository;

    public function __construct(TestRepository $repository)
    {
        $this->repository = $repository;
    }

    public function getAllTest()
    {
        return $this->repository->all();
    }

    public function createTest(array $data)
    {
        return $this->repository->create($data);
    }

    public function updateTest(mixed $id, array $data)
    {
        return $this->repository->update($id, $data);
    }

    public function deleteTest(mixed $ids)
    {
        return $this->repository->delete($ids);
    }
    
}

逐个创建 View Blade

创建视图。
php artisan make:view {--print} {viewName}

示例

php artisan make:view testview

结果

/resources/views/testview.blade.php

许可证

MIT 许可证(MIT)。更详细的信息请参阅许可证。