php larval开发规范,GitHub - cqcqs/laravel-modules: 基于Laravel7项目开发规范

laravel-modules

基于 Laravel7 实现的一套开发规范,在原路由层(Route)、控制器层(Controller)上增加数据传输层(DTO)、业务逻辑层(Service)、数据映射层(Repository),并且建议以面向对象的思想进行开发。

Route(路由) > MiddleWare(中间件) > Request(表单验证) > Controller(控制器) > DTO(数据传输层) > Service(业务逻辑层) > Repository(数据映射层) > Model(模型)

项目正逐步完善中……

Controller

Demo

public function list() : ResponseHelper

{

$commonDTO = new CommonDTO([

'id' => $request->post('id')

]);

return ServiceHelper::make('Api\\V1\\LiveService')->list($commonDTO);

}

DTO

$commonDTO = new CommonDTO();

$commonDTO->setId(request()->route('id'));

Service

php artisan make:service LiveService;

LiveService.php

ServiceHelper::make('Api\\V1\\LiveService')->list($commonDTO);

class LiveService extends Service

{

/**

* @param CommonDTO $commonDTO

* @return ResponseHelper

*/

public function list(CommonDTO $commonDTO) : ResponseHelper

{

}

}

Repository

php artisan make:model Models/Live

php artisan make:repository LiveRepository

LiveRepository.php

use App\Models\Live;

public function model()

{

return Live::class;

}

LiveService.php

public function __construct(LiveRepository $live)

{

$this->live = $live;

}

/**

* @return ResponseHelper

*/

public function list() : ResponseHelper

{

$list = $this->live->all();

$response = new ResponseHelper();

$response->setData($list->toArray());

return $response;

}

Links

laravel-mode:laravel-mode

正在完善,并且后期将提供composer包安装

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值