# Auto-generate error code component ## Description Ability to automatically maintain error code generation based on the given rules。 > The code parameter in the convention return data, all custom codes, positive numbers for normal service, negative numbers for abnormal service。 ## Project address https://github.com/teamones-open/response-code-msg ## Install ```php composer require teamones/response-code-msg ``` ## Usage ### empty ErrorCode class file - File path ./support/ErrorCode.php ```php new \support\ErrorCode(), // ErrorCode class file "root_path" => app_path(), // Current Code Root "system_number" => 201, // System identification "start_min_number" => 10000 // Error code generation range e.g. 10000-99999 ]; ``` ### Add automatic error code generation for startup in start.php - File path ./start.php ```php // put Config::load(config_path(), ['route', 'container']); back // Generate error codes, only in APP_DEBUG mode if (config("app.debug")) { $errorCodeConfig = config('error_code'); (new \teamones\responseCodeMsg\Generate($errorCodeConfig))->run(); } ``` ### Use in code is a single instance **ErrorCode::ModelAddOptionsError** is an error code, where **ModelAddOptionsError** It needs to be written by the user with semantic initial capitalization according to the current requirements。 > After writing you will find that it is unusable, and then the next reboot will automatically generate the corresponding error code. Note that sometimes you need to restart twice。 ```php $value) { $demo->$key = $value; } $demo->save(); return $demo->getData(); } catch (\Throwable $e) { // Output error message throw_http_exception($e->getMessage(), ErrorCode::ModelAddOptionsError); } return []; } } ``` ### The generated . /support/ErrorCode.php file ```php