ikechukwukalu/makeservice
Composer 安装命令:
composer require ikechukwukalu/makeservice
包简介
A laravel package for scaffolding service classes.
README 文档
README
A laravel package for scaffolding Service, Traits, Enums, Facades, Actions, Repository and Interface classes.
REQUIREMENTS
- PHP 7.3+
- Laravel 8+
STEPS TO INSTALL
composer require ikechukwukalu/makeservice
SERVICE CLASS
To generate a new service class.
php artisan make:service SampleService php artisan make:service SampleService -f //This will overwrite an existing service class.
To generate a new service class for a particular request class.
php artisan make:request SampleRequest php artisan make:service SampleService --request=SampleRequest
To generate a service class and a form request class together
php artisan make:service SampleService --request=SampleRequest -e
TRAIT CLASS
To generate a new trait class.
php artisan make:traitclass SampleTrait php artisan make:traitclass SampleTrait -f //This will overwrite an existing trait class.
ENUM CLASS
To generate a new enum class.
php artisan make:enumclass Sample php artisan make:enumclass Sample -f //This will overwrite an existing enum class.
ACTION CLASS
To generate a new action class.
php artisan make:action Sample php artisan make:action Sample -f //This will overwrite an existing action class.
CONTRACT CLASS
To generate a new contract/interface class.
php artisan make:interfaceclass SampleInterface php artisan make:interfaceclass SampleInterface -f //This will overwrite an existing interface class.
REPOSITORY CLASS
To generate a new repository class for a particular contract/interface class.
php artisan make:interfaceclass UserRepositoryInterface --model=User php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface -f //This will overwrite an existing repository class.
To generate extra fetch by user id methods.
php artisan make:interfaceclass UserRepositoryInterface --model=User --user php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface --user php artisan make:repository UserRepository --model=User --interface=UserRepositoryInterface --user -f //This will overwrite an existing repository class.
To generate a repository class and a contract/interface class together
php artisan make:repository UserRepository --model=User -c php artisan make:repository UserRepository --model=User --user -c
FACADE CLASS
To generate a new facade class.
php artisan make:facade Sample php artisan make:facade Sample -f //This will overwrite an existing facade class.
To generate a facade class for a repository class
php artisan make:facade User --contract=UserRepositoryInterface
Bind the contract and the repository class
The last thing we need to do is bind UserRepository to UserRepositoryInterface in Laravel's Service Container. We will do this via a Service Provider. Create one using the following command:
php artisan make:provider RepositoryServiceProvider
Open app/Providers/RepositoryServiceProvider.php and update the register function to match the following:
public function register() { $this->app->bind(UserRepositoryInterface::class, UserRepository::class); }
Finally, add the new Service Provider to the providers array in config/app.php.
'providers' => [ // ...other declared providers App\Providers\RepositoryServiceProvider::class, ];
Bind the facade and the action class
If we have a User facade class and a UserService action class, we would need to add it to Laravel's Service Container. Facades for respository classes will work without any extra binding since they have already been added to the container within the RepositoryServiceProvider class, but we would always need to register every facade class we created.
Create the provider:
php artisan make:provider FacadeServiceProvider
Bind the action class:
public function register() { $this->app->bind('user', UserService::class); }
Register the providers:
'providers' => [ // ...other declared providers App\Providers\FacadeServiceProvider::class, App\Providers\RepositoryServiceProvider::class, ];
Finally, add the facade to the aliases array in config/app.php.
'aliases' => Facade::defaultAliases()->merge([ // ...other declared facades 'User' => App\Facades\User::class, ])->toArray(),
LICENSE
The MS package is an open-sourced software licensed under the MIT license.
ikechukwukalu/makeservice 适用场景与选型建议
ikechukwukalu/makeservice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.21k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2023 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ikechukwukalu/makeservice 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ikechukwukalu/makeservice 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-23