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包安装