定制 garmonic/laravel-features-arch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

garmonic/laravel-features-arch

Composer 安装命令:

composer require garmonic/laravel-features-arch

包简介

This package helps you to divide you Laravel project code by features, encapsulated in separate folders. Each feature has its own container, configuration, routes, views and providers. You can enable and disable your features in general config file.

README 文档

README

Description

This package helps you to divide your Laravel project code by features, encapsulated in separate folders. Each feature has its own container, configuration, routes, views and providers. You can enable and disable your features in general config file.

Installation

  1. Use following composer command in your terminal:

composer require garmonic/laravel-features-arch

If file config/features.php has not been created, run such command:

php artisan vendor:publish --provider='Garmonic\FeaturesArch\Providers\FeatureServiceProvider'

  1. Add to composer.json file (section "psr-4" in "autoload") following string:

"Features\\": "features/",

Usage

Creating new feature

To create new feature, run console command:

php artisan make:feature with name of your feature, for example:

php artisan make:feature Warehouse

If you wish to specify routes beginning for feature, use option route with its value, example for beginning /wh/:

php artisan make:feature Warehouse --route=wh

Route base should not start with slash, but can contain it inside. By default, route base will be made from feature name converted to lower case.All routes will be automatically prefixed by specified or generated beginning.

Finally, new folder /features/{your-feature-name} will appear in your project. It will be place of new feature.

Enabling and disabling features

To enable feature, add its name and main class name (Features\\{name}\\Feature::class) to config/features.php (section "list").

To disable it, comment its string in the same config file.

Feature folder files structure

  • config/main.php — empty config file for feature.

You can read config from it using Feature::config(). In controller: $this->feature->config('main.config_key', 'default');

Also you can add your own config files to feature config folder and use them in the same way.

  • Core/Http/Controllers/MainController — empty controller with one demo method.

You can create your own controllers for feature, each of them should extend Garmonic\FeaturesArch\BaseController and contain correct featureName property.

  • Core/Providers/MainServiceProvider.php — empty service provider, you are welcome to add there some bindings (as you do in AppServiceProvider), that will be actual for this feature.

You can use global container (App::singleton() or App::bind()) or feature container ($this->feature->singleton() or $this->feature->bind()).

  • Core/Providers/RouteServiceProvider.php — this service provider is responsible for loading feature routes. Be careful while changing its code.
  • resources/views/home.blade.php — sample view.

You can add your own views and use them in controllers like this: return $this->feature->view('view_name', ['data'=>'some_data']); Also, each view has $feature variable to have access to feature instance.

  • routes/api.php — empty API routes file.
  • routes/web.php — web routes file with demo route.

Links to feature routes can be generated using Feature::route() method.

In controller: $this->feature->route('route_name', ['data'=>'some_data']);

In view: {{ $feature->route('route_name', ['data'=>'some_data']) }}

About author

Alexey Vasilyev, https://github.com/garmonic

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固