# Plugin mechanism

# Principle

The BeikeShop plugin makes full use of the Laravel framework ServiceProvider discovery and boot mechanism to register various plugins in the system. Including the plugin's Migrations, Routes, Views, Lang, and the startup file Bootstrap.php.

Plugin PHP code needs to follow the PSR4 autoloading specification.

In short, directory names and class names need to use the first letter of the capital camel case, which is the Studly principle, as shown in the figure

img.png

# Catalog Description

A typical plugin directory is as follows

  • Controllers
  • Lang
  • Middleware
  • Migrations
  • Models
  • Repositories
  • Routes
  • Static
  • Views
  • Bootstrap.php
  • columns.php
  • config.json
Directory Name illustrate
Controllers Controller directory. Both the front-end and back-end controllers are placed in this directory. There can be sub-directories as long as they comply with the PSR4 specification.
Lang Language pack directory, the subdirectory name needs to be consistent with the /resources/lang directory
Middleware Middleware directory, subdirectory /Shop stores front-end middleware, subdirectory /Admin stores back-end middleware, the system will automatically load
Migrations Database migration directory, please refer to https://laravel.com/docs/9.x/migrations
Models Model directory, plug-in model, define model data tables and relationships between tables
Repositories Data warehouse directory, DB access related classes
Routes Routing directory, plugin custom routing. admin.php stores management backend routing, shop.php stores frontend routing
Static Static files, such as images, can be placed in the image directory and referenced in the corresponding plugin template file using the helper plugin_resize(plugin code, '/image/xx.png')
Views Plugin template directory, including front-end and back-end blade.php template files
Bootstrap.php The plugin startup class needs to implement a boot public method: public function boot(), and then add a hook to this method
columns.php Plugin configuration. This file stores the configuration fields required by the plugin, and the background plugin editing page will be automatically displayed. If you need a custom configuration page, please add the /Views/admin/config.blade.php template file under the plugin
config.json Basic information of the plugin, including code, name, description, type, icon, author, etc.