moraesgil/api-restful-trait
Composer 安装命令:
composer require moraesgil/api-restful-trait
包简介
A simple Laravel trait with restful crud implementation.
关键字:
README 文档
README
A simple Laravel trait with restful crud implementation.
Installation
With Composer
$ composer require moraesgil/api-restful-trait
{
"require": {
"moraesgil/api-restful-trait": "~1.0"
}
}
Usage
create your routes in routes/api.php or your prefer routes file
Route::resource('/samples', 'YourLaravelController', ['except' => ['create', 'edit', 'show']]);
make sure you have a model at App\Entities\YourModel same name of controller to Autoload model entity, or you can inject dependencies, see bellow the following instructions in Extras area...
//terminal
php artisan make model YourLaravel
In your Controller
use Traits\Controllers\ApiRestfulTrait; //<<<<< add this line class YourLaravelController extends Controller { use ApiRestfulTrait; //<<<<< add this line // ..others non-crud methods }
Include the EntityValidatorTrait it's a dependency. Please check documentation for more info. Also read about Autoload model entity in this extras section.
use Traits\Entities\EntityValidatorTrait; //<<<<< add this line class YourLaravel extends Model { use EntityValidatorTrait; //<<<<< add this line }
Extras
Getting an index page
May you have to call a page in index() if not ajax request, we have getPage(), can you override method or just to pass data by constructor, also you can redirect to another page passing the route name;
//in or controller you can pass class YourLaravelController extends Controller { public function __construct() { //Passing view and data $this->indexView = "youCrudBlade"; //default "crud" $this->indexData = [ "pageTitle" => "Page title for exemple" ]; // OR redirect to named route $this->indexRedirectRouteName ="myroute.indexpage" } }
Autoload model entity
By default it try access a model with same name of controller, you can to pass your entity by name or object in constructor
class YourLaravelController extends Controller { public function __construct(Mymodel $m) { $this->Model = $m; // or $this->modelName = "Mymodel"; // or Just create a model same name of controller, from this controller sample "YourLaravel" } }
Getting data from Entity custom method
By default it return a Laravel paginate getting limit by request, can you override method or call a customMethod from your entitiy passing $modelGetMethod
class YourLaravelController extends Controller { public function __construct() { $this->modelGetMethodName = "myCustomPaginate"; } }
Dependencies
- EntityValidatorTrait - My trait to allow model do self validation - EntityValidatorTrait
Authors
- Gilberto Prudêncio Vaz de Moraes - Initial work - MoraesGil
License
This project is licensed under the MIT License - see the LICENSE file for details
moraesgil/api-restful-trait 适用场景与选型建议
moraesgil/api-restful-trait 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「model」 「laravel」 「entity」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moraesgil/api-restful-trait 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moraesgil/api-restful-trait 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moraesgil/api-restful-trait 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Interfaces for web resource models and services to retrieve and create them
Laravel 5 - Repositories to the database layer
This package provides an Address Model, Migration and Factory. It also provides the traits HasBillingAddres and HasPublicAddress
The YADM migrations
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-29