承接 moraesgil/api-restful-trait 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

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

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固