bleuren/laravel-api
Composer 安装命令:
composer require bleuren/laravel-api
包简介
A package to develop APIs with Laravel using Repository and Service patterns
README 文档
README
A robust Laravel package for implementing the Repository and Service patterns in your API development. This package provides a solid foundation for building scalable and maintainable APIs by separating concerns and promoting clean code architecture.
Features
- Base Repository and Service classes
- Artisan commands for generating Repositories and Services
- Automatic binding of Repositories and Services in the Service Container
- JSON response handling
- Easy integration with Laravel projects
Requirements
- PHP 8.2+
- Laravel 11.0+
Installation
- Add the package to your Laravel project:
composer require bleuren/laravel-api
- Publish the package configuration (optional):
php artisan vendor:publish --provider="Bleuren\LaravelApi\Providers\LaravelApiServiceProvider" --tag="config"
Usage
Creating a Repository
To create a new repository, use the following Artisan command:
php artisan make:repository User
This will create a new UserRepository class in the app/Repositories directory and a corresponding UserRepositoryInterface in the app/Contracts directory.
Creating a Service
To create a new service, use the following Artisan command:
php artisan make:service User
This will create a new UserService class in the app/Services directory and a corresponding UserServiceInterface in the app/Contracts directory.
Using Repositories and Services in Controllers
After creating your repositories and services, you can use them in your controllers like this:
use App\Contracts\UserServiceInterface; class UserController extends Controller { protected $userService; public function __construct(UserServiceInterface $userService) { $this->userService = $userService; } public function index() { return $this->userService->all(); } public function show($id) { return $this->userService->find($id); } // ... other methods }
Extending Base Classes
You can extend the base Repository and Service classes to add custom functionality:
use Bleuren\LaravelApi\BaseRepository; use App\Models\User; class UserRepository extends BaseRepository { public function __construct(User $model) { parent::__construct($model); } // Add custom methods here }
use Bleuren\LaravelApi\BaseService; use App\Contracts\UserRepositoryInterface; class UserService extends BaseService { public function __construct(UserRepositoryInterface $repository) { parent::__construct($repository); } // Add custom methods here }
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
bleuren/laravel-api 适用场景与选型建议
bleuren/laravel-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 822 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「repository」 「service」 「laravel」 「bleuren」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bleuren/laravel-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bleuren/laravel-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bleuren/laravel-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A fast and intuitive dependency injection container.
A PSR-7 compatible library for making CRUD API endpoints
Registry service.
Laravel 5 - Repositories to the database layer
swagger-php - Generate interactive documentation for your RESTful API using phpdoc annotations
统计信息
- 总下载量: 822
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-02