owowagency/laravel-resources
Composer 安装命令:
composer require owowagency/laravel-resources
包简介
A package to develop projects faster.
关键字:
README 文档
README
Sick and tired of having to create the same controller over and over?
Look no further! OWOW presents "Laravel Resources".
A package that makes creating API endpoints feel like breeze.
📖 Table of contents
⚙️ Installation
composer require owowagency/laravel-resources
🛠 Usage
This package adds a few new features to the already existing apiResource method, model and requests.
model will be used to determine what model is being be handled.
requests should contain the form requests that are used to validate incoming data during creation and updating.
Route registration
use App\Http\Requests\Posts\StoreRequest; use App\Http\Requests\Posts\UpdateRequest; use App\Models\Post; use OwowAgency\LaravelResources\Controllers\ResourceController; Route:apiResource( 'posts', ResourceController::class, [ 'model' => Post::class, 'requests' => [ 'store' => StoreRequest::class, 'update' => UpdateRequest::class, ], ], );
Customizing controllers
All methods in the ResourceController can be overwritten. We made it a little easier by adding methods like indexModel, and updateModel. You will not have to worry about validating, authorization, or returning the models as response.
use OwowAgency\LaravelResources\Controllers\ResourceController; class PostController extends ResourceController { /** * Returns models instances used for the index action. * * @return mixed */ public function indexModel() { return Post::where('title', 'LIKE', request('search'))->paginate(); } /** * Updates and returns the model instance for the update action. * * @param \Illuminate\Http\Request $request * @param \Illuminate\Database\Eloquent\Model $model * @return void */ public function updateModel(Request $request, Model $model) { $model->update(['user_id' => \Auth::user()->id]); } }
Eloquent API resources
This package will always try to return the API resource representation of the specified model. It applies auto discovery to determine what resource to use.
By default it will use the following pattern to discover the resource class:
App\Http\Resources\{class_baseName($modelClass)}Resource
In case of a Post model that will become:
App\Http\Resources\PostResource
Configuration
Configuration can be published with:
php artisan vendor:publish --tag=laravelresources
return [ /** * Is used for auto discovery of http resources. Allows for placing * resources under a different namespace. */ 'resource_namespace' => 'App\\Http\\Resources', /** * Configure resources that do not follow the default auto discovery rules. * * Eg: * [Post::class => SpecialPostResource::class] */ 'resource_factory' => [], ];
🫶 Contributing
Please see CONTRIBUTING for details.
📜 License
The MIT License (MIT). Please see License File for more information.
This package has been brought to you with much love by the wizkids of OWOW. Do you like this package? We’re still looking for new talent and Wizkids. So do you want to contribute to open source, while getting paid? Apply now
owowagency/laravel-resources 适用场景与选型建议
owowagency/laravel-resources 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.06k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 10 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「resources」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 owowagency/laravel-resources 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 owowagency/laravel-resources 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 owowagency/laravel-resources 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Resource group sub-menus for Laravel Nova.
Payment resources library used by the official CCV Payment Services plugins
Filament package to prevent the update of outdated records.
Conveniant factory for Laravel API resources
A simple resource watcher using Symfony Finder
Resources for the website (CSS, JS files)
统计信息
- 总下载量: 12.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 6
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-30