2 Star 1 Fork 0

liuweiliang / example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
INSTALL-B.md 38.80 KB
一键复制 编辑 原始数据 按行查看 历史
lwlzq 提交于 2021-11-29 19:03 . add csrf

方法b

b-1 获取全新 Laravel 5.8 框架

  b-1-1、composer create-project --prefer-dist laravel/laravel example "5.8.*"
  b-1-2、获取 laravel 新框架 需 按照以下步骤一步一步执行 直到 看到  ----方法 b END--- 

b-2 根据 表格中目录层级 创建 开发模块

文件 功能描述
_example 主业务开发目录
_example\Constants 定义契约
_example\Controller 控制器
_example\Controller\Staff 员工后台控制器
_example\Controller\Index 对外控制器
_example\Controller\Inner 微服务提供服务控制器
_example\Controller\Member app 控制器
_example\Controller\Task 计划任务 控制器
_example\Controller\TestController 测试 控制器
_example\Helpers 全局工具类 定义 全局函数
_example\Helpers\functions.php 全局工具函数
_example\Models 模型层
_example\Requests 验证层
_example\Services 服务层
_example\Services\Task 服务层 计划任务
_example\Filters 模型过滤层
_example\routes 路由文件
_example\routes\route.php 基类路由文件
_example\index_route.php 公共(无鉴权)路由
_example\task_route.php 计划任务(无鉴权)路由
_example\member_route.php app 会员路由
_example\staff_route.php 后台员工路由
_example\inner_route.php 微服务提供api路由
_example\basic_route.php 基础api路由
_example\config\common.php 全局配置 redis 的 key 分页页码 等的定义
_example\ecosystem.config.js 启动队列文件
_example\bash\release.sh 发布版本执行命令
_example\bash\give_log_permissions.sh 赋予log 权限
_example\bash\init.sh 搭建框架初始化

b-3 创建 .env 并写入以下内容 到 .env ,并配置正确的数据库 和 Redis 配置

### 应用相关
APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost
API_GATEWAY=http://api-internal-dev.shall-buy.top
APP_KEY=base64:gGqkzvlocuR62bRpw9K1mWklXbWNZruJIn6iEqheaFQ=

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=rm_sdfadfa-bp130dahx82uk26a0.mysql.rds.aliyuncs.com
DB_PORT=3306
DB_DATABASE=数据库名称
DB_USERNAME=sdsa_local_user
DB_PASSWORD=sdsa_dev123456!

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=r-bp18sjpws29jeq1229.redis.rds.aliyuncs.com
REDIS_PASSWORD=xiaobadev123!!
REDIS_PORT=6379
YIMQ_DEFALUT_SERVICE_URI=http://yimq-svc:7379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

WRITE_SQL_LOG=false

b-4 项目根目录下 创建 nginx.conf 并写入以下内容

server {
    listen 80;
    server_name example.test; # 虚拟域名 域名须 .test 
    root /workspace/xiaoba/example/public; #项目所在路径 记得项目要配置在 /workspace/xiaoba/ 下 别问为啥 容器里 nginx.conf 就是这么定义的
    
        location / {
            include  fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        }
}

b-5 将以下内容覆盖到 composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "type": "project",
    "repositories": [
        {
            "type": "vcs",
            "url": "git@git.shall-buy.top:xiaoba/login-security.git"
        },
        {
            "type": "vcs",
            "url": "git@git.shall-buy.top:shallbuy/laravel-base.git"
        },
        {
            "type": "vcs",
            "url": "git@git.shall-buy.top:xiaoba/micro-api.git"
        },
        {
            "type": "vcs",
            "url": "git@git.shall-buy.top:xiaoba/form-res.git"
        },
        {
            "type": "vcs",
            "url": "http://share-git.shall-buy.top/yilu/laravel-passport.git"
        },
        {
            "type": "vcs",
            "url": "http://share-git.shall-buy.top/yilu/laravel-validation.git"
        },
        {
            "type": "vcs",
            "url": "http://share-git.shall-buy.top/yilu/laravel-gateway.git"
        },
        {
            "type": "vcs",
            "url": "http://share-git.shall-buy.top/yilu/complex-search.git"
        },
        {
            "type": "vcs",
            "url": "http://share-git.shall-buy.top/yilu/permission.git"
        }
    ],
    "require": {
        "php": "^7.1.3",
        "doctrine/dbal": "2.9.*",
        "barryvdh/laravel-ide-helper": "^2.5",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/socialite": "^4.4",
        "laravel/tinker": "^1.0",
        "latrell/rongcloud": "dev-master",
        "lcobucci/jwt": "3.3.3",
        "maatwebsite/excel": "3.1.*",
        "mxy/form-res": "dev-master",
        "predis/predis": "^1.1",
        "shall-buy/laravel-base": "dev-master",
        "shall-buy/login-security": "dev-master",
        "shall-buy/micro-api": "0.5.8.0",
        "simplesoftwareio/simple-qrcode": "~2",
        "yankewei/laravel-sensitive": "^2.0",
        "yilu-tech/complex-search": "1.5.8.0",
        "yilu-tech/laravel-gateway": "1.5.8.0",
        "yilu-tech/laravel-passport": "0.5.8.0",
        "yilu-tech/laravel-validation": "0.5.8.0",
        "yilu-tech/permission": "2.5.8.0",
        "yilu-tech/yimq-laravel-sdk": "dev-0.5.8.3-fix-1",
        "zgldh/qiniu-laravel-storage": "^0.10.1",
        "itbdw/ip-database": "^2.0"
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\\": "app/",
            "Example\\": "_example/" *** 将 Example 改成你的 命名空间名称,将 _example 改成你的 文件目录
        },
        "files":[
            "_example/Helpers/functions.php" # *** 将 _example 改成你的 文件目录
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan ide-helper:generate",
            "php artisan ide-helper:meta"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "secure-http": false
    },
    "minimum-stability": "stable",
    "prefer-stable": true
}

b-6 更改命名空间

b-5-1、将 _example 所有文件的 命名空间 改成 composer.json 下 autoload->psr-4 下 所定义的 命名空间

b-7 创建 Dockerfile 并 写入以下内容

FROM yilutech/phpfpm:7.4

COPY . /apps/

b-8 将以下内容 覆盖到 example/bootstrap/app.php


<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    $_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    Illuminate\Contracts\Http\Kernel::class,
    App\Http\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Console\Kernel::class,
    App\Console\Kernel::class
);

$app->singleton(
    Illuminate\Contracts\Debug\ExceptionHandler::class,
    ShallBuy\LaravelBase\Common\Exception\Handler::class # 用 ShallBuy 抛出异常
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

b-9 将以下内容覆盖到 Kernel.php

<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        \App\Http\Middleware\TrustProxies::class,
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
//        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, # 本框架注释不打开
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',

            \ShallBuy\LaravelBase\Common\Middleware\StandardizeResponse::class,//响应格式
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
        'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
        'can' => \Illuminate\Auth\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

        'staff.auth' => \ShallBuy\LaravelBase\Staff\Middleware\AuthMiddleware::class,
        'member.auth' => \ShallBuy\LaravelBase\Member\Middleware\AuthMiddleware::class,
        'user.auth' => \ShallBuy\LaravelBase\Store\Middleware\AuthMiddleware::class,
        //'csrf' => Csrf::class, //csrf 防护
    ];

    /**
     * The priority-sorted list of middleware.
     *
     * This forces non-global middleware to always be in the given order.
     *
     * @var array
     */
    protected $middlewarePriority = [
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\Authenticate::class,
        \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
        \Illuminate\Auth\Middleware\Authorize::class,
    ];
}

b-10.将以下内容覆盖到 config/app.php

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Application Name
    |--------------------------------------------------------------------------
    |
    | This value is the name of your application. This value is used when the
    | framework needs to place the application's name in a notification or
    | any other location as required by the application or its packages.
    |
    */

    'name' => env('APP_NAME', 'Laravel'),

    /*
    |--------------------------------------------------------------------------
    | Application Environment
    |--------------------------------------------------------------------------
    |
    | This value determines the "environment" your application is currently
    | running in. This may determine how you prefer to configure various
    | services the application utilizes. Set this in your ".env" file.
    |
    */

    'env' => env('APP_ENV', 'production'),

    /*
    |--------------------------------------------------------------------------
    | Application Debug Mode
    |--------------------------------------------------------------------------
    |
    | When your application is in debug mode, detailed error messages with
    | stack traces will be shown on every error that occurs within your
    | application. If disabled, a simple generic error page is shown.
    |
    */

    'debug' => env('APP_DEBUG', false),

    /*
    |--------------------------------------------------------------------------
    | Application URL
    |--------------------------------------------------------------------------
    |
    | This URL is used by the console to properly generate URLs when using
    | the Artisan command line tool. You should set this to the root of
    | your application so that it is used when running Artisan tasks.
    |
    */

    'url' => env('APP_URL', 'http://localhost'),

    'asset_url' => env('ASSET_URL', null),

    /*
    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    */

    'timezone' => 'Asia/Shanghai',

    /*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'zn',

    /*
    |--------------------------------------------------------------------------
    | Application Fallback Locale
    |--------------------------------------------------------------------------
    |
    | The fallback locale determines the locale to use when the current one
    | is not available. You may change the value to correspond to any of
    | the language folders that are provided through your application.
    |
    */

    'fallback_locale' => 'zn',

    /*
    |--------------------------------------------------------------------------
    | Faker Locale
    |--------------------------------------------------------------------------
    |
    | This locale will be used by the Faker PHP library when generating fake
    | data for your database seeds. For example, this will be used to get
    | localized telephone numbers, street address information and more.
    |
    */

    'faker_locale' => 'en_US',

    /*
    |--------------------------------------------------------------------------
    | Encryption Key
    |--------------------------------------------------------------------------
    |
    | This key is used by the Illuminate encrypter service and should be set
    | to a random, 32 character string, otherwise these encrypted strings
    | will not be safe. Please do this before deploying an application!
    |
    */

    'key' => env('APP_KEY'),

    'cipher' => 'AES-256-CBC',

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,

        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

        //App\Providers\MicroServiceProvider::class,//调用其他服务 的服务提供者,

    ],

    /*
    |--------------------------------------------------------------------------
    | Class Aliases
    |--------------------------------------------------------------------------
    |
    | This array of class aliases will be registered when this application
    | is started. However, feel free to register as many as you wish as
    | the aliases are "lazy" loaded so they don't hinder performance.
    |
    */

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Arr' => Illuminate\Support\Arr::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,
        'Auth' => Illuminate\Support\Facades\Auth::class,
        'Blade' => Illuminate\Support\Facades\Blade::class,
        'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
        'Bus' => Illuminate\Support\Facades\Bus::class,
        'Cache' => Illuminate\Support\Facades\Cache::class,
        'Config' => Illuminate\Support\Facades\Config::class,
        'Cookie' => Illuminate\Support\Facades\Cookie::class,
        'Crypt' => Illuminate\Support\Facades\Crypt::class,
        'DB' => Illuminate\Support\Facades\DB::class,
        'Eloquent' => Illuminate\Database\Eloquent\Model::class,
        'Event' => Illuminate\Support\Facades\Event::class,
        'File' => Illuminate\Support\Facades\File::class,
        'Gate' => Illuminate\Support\Facades\Gate::class,
        'Hash' => Illuminate\Support\Facades\Hash::class,
        'Lang' => Illuminate\Support\Facades\Lang::class,
        'Log' => Illuminate\Support\Facades\Log::class,
        'Mail' => Illuminate\Support\Facades\Mail::class,
        'Notification' => Illuminate\Support\Facades\Notification::class,
        'Password' => Illuminate\Support\Facades\Password::class,
        'Queue' => Illuminate\Support\Facades\Queue::class,
        'Redirect' => Illuminate\Support\Facades\Redirect::class,
        'Redis' => Illuminate\Support\Facades\Redis::class,
        'Request' => Illuminate\Support\Facades\Request::class,
        'Response' => Illuminate\Support\Facades\Response::class,
        'Route' => Illuminate\Support\Facades\Route::class,
        'Schema' => Illuminate\Support\Facades\Schema::class,
        'Session' => Illuminate\Support\Facades\Session::class,
        'Storage' => Illuminate\Support\Facades\Storage::class,
        'Str' => Illuminate\Support\Str::class,
        'URL' => Illuminate\Support\Facades\URL::class,
        'Validator' => Illuminate\Support\Facades\Validator::class,
        'View' => Illuminate\Support\Facades\View::class,

        'ExceptionFactory' => \ShallBuy\LaravelBase\Common\Exception\ExceptionFactoryFacade::class,
        'Api' => \ShallBuy\MicroApi\MicroApiFacade::class,
        'SharedCache' => \ShallBuy\LaravelBase\Shared\SharedCacheFacade::class,
        'Sensitive' => \ShallBuy\LaravelBase\Sensitive\SensitiveFancade::class

    ],

];

b-11.创建文件 /resources/lang/zn/validation.php 并写入以下内容

return [

    /*
    |--------------------------------------------------------------------------
    | Validation Language Lines
    |--------------------------------------------------------------------------
    |
    | The following language lines contain the default error messages used by
    | the validator class. Some of these rules have multiple versions such
    | as the size rules. Feel free to tweak each of these messages here.
    |
    */

    'accepted'             => ':attribute必须接受',
    'active_url'           => ':attribute必须是一个合法的 URL',
    'after'                => ':attribute 必须是 :date 之后的一个日期',
    'after_or_equal'       => ':attribute 必须是 :date 之后或相同的一个日期',
    'alpha'                => ':attribute只能包含字母',
    'alpha_dash'           => ':attribute只能包含字母、数字、中划线或下划线',
    'alpha_num'            => ':attribute只能包含字母和数字',
    'array'                => ':attribute必须是一个数组',
    'before'               => ':attribute 必须是 :date 之前的一个日期',
    'before_or_equal'      => ':attribute 必须是 :date 之前或相同的一个日期',
    'between'              => [
    'numeric' => ':attribute 必须在 :min 到 :max 之间',
    'file'    => ':attribute 必须在 :min 到 :max KB 之间',
    'string'  => ':attribute 必须在 :min 到 :max 个字符之间',
    'array'   => ':attribute 必须在 :min 到 :max 项之间',
    ],
    'boolean'              =>':attribute字符必须是 true 或false, 1 或 0 ',
    'confirmed'            => ':attribute 二次确认不匹配',
    'date'                 => ':attribute 必须是一个合法的日期',
    'date_format'          => ':attribute 与给定的格式 :format 不符合',
    'different'            => ':attribute 必须不同于 :other',
    'digits'               => ':attribute必须是 :digits 位.',
    'digits_between'       => ':attribute 必须在 :min 和 :max 位之间',
    'dimensions'           => ':attribute具有无效的图片尺寸',
    'distinct'             => ':attribute字段具有重复值',
    'email'                => ':attribute必须是一个合法的电子邮件地址',
    'exists'               => '选定的 :attribute 是无效的.',
    'file'                 => ':attribute必须是一个文件',
    'filled'               => ':attribute的字段是必填的',
    'image'                => ':attribute必须是 jpeg, png, bmp 或者 gif 格式的图片',
    'in'                   => '选定的 :attribute 是无效的',
    'in_array'             => ':attribute 字段不存在于 :other',
    'integer'              => ':attribute 必须是个整数',
    'ip'                   => ':attribute必须是一个合法的 IP 地址。',
    'json'                 => ':attribute必须是一个合法的 JSON 字符串',
    'max'                  => [
    'numeric' => ':attribute 的最大值为:max',
    'file'    => ':attribute 的最大为 :max',
    'string'  => ':attribute 的最大长度为 :max 字符',
    'array'   => ':attribute 的最大个数为 :max 个.',
    ],
    'mimes'                => ':attribute 的文件类型必须是 :values',
    'min'                  => [
    'numeric' => ':attribute 的最小值为:min',
    'file'    => ':attribute 大小至少为 :min KB',
    'string'  => ':attribute 的最小长度为 :min 字符',
    'array'   => ':attribute 至少有 :min 项',
    ],
    'not_in'               => '选定的 :attribute 是无效的',
    'numeric'              => ':attribute 必须是数字',
    'present'              => ':attribute 字段必须存在',
    'regex'                => ':attribute 格式是无效的',
    'required'             => '请填写:attribute',
    'required_if'          => ':attribute 字段是必须的当 :other 是 :value',
    'required_unless'      => ':attribute 字段是必须的,除非 :other 是在 :values 中',
    'required_with'        => ':attribute 字段是必须的当 :values 是存在的',
    'required_with_all'    => ':attribute 字段是必须的当 :values 是存在的',
    'required_without'     => ':attribute 字段是必须的当 :values 是不存在的',
    'required_without_all' => ':attribute 字段是必须的当 没有一个 :values 是存在的',
    'same'                 => ':attribute和:other必须匹配',
    'size'                 => [
        'numeric' => ':attribute 必须是 :size 位',
        'file'    => ':attribute 必须是 :size KB',
        'string'  => ':attribute 必须是 :size 个字符',
        'array'   => ':attribute 必须包括 :size 项',
    ],
    'string'               => ':attribute 必须是一个字符串',
    'timezone'             => ':attribute 必须是个有效的时区.',
    'unique'               => ':attribute 已存在',
    'url'                  => ':attribute 无效的格式',

/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
|--------------------------------------------------------------------------
|
| Here you may specify custom validation messages for attributes using the
| convention "attribute.rule" to name the lines. This makes it quick to
| specify a specific custom language line for a given attribute rule.
|
*/

'custom' => [
    'attribute-name' => [
        'rule-name' => 'custom-message',
    ],
],

/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap attribute place-holders
| with something more reader friendly such as E-Mail Address instead
| of "email". This simply helps us make messages a little cleaner.
|
*/

    'attributes' => [
        'public_key'=>'公钥',
        'sign'=>'签名',
        'timestamp'=>'时间',
    ],

];

b-12 将以下内容覆盖 config/database.php

<?php

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer body of commands than a typical key-value system
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => env('REDIS_CLIENT', 'predis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'predis'),
            'prefix' => env('APP_NAME').'-prefix:',
        ],

        'default' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],

        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_CACHE_DB', 1),
        ],

    ],

];

b-13 将以下内容覆盖到 config/logging.php

<?php

use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |--------------------------------------------------------------------------
    | Log Channels
    |--------------------------------------------------------------------------
    |
    | Here you may configure the log channels for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Drivers: "single", "daily", "slack", "syslog",
    |                    "errorlog", "monolog",
    |                    "custom", "stack"
    |
    */

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['daily'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
            'days' => 14,
            'permission' => 0664,
        ],

        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'papertrail' => [
            'driver' => 'monolog',
            'level' => 'debug',
            'handler' => SyslogUdpHandler::class,
            'handler_with' => [
                'host' => env('PAPERTRAIL_URL'),
                'port' => env('PAPERTRAIL_PORT'),
            ],
        ],

        'stderr' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'formatter' => env('LOG_STDERR_FORMATTER'),
            'with' => [
                'stream' => 'php://stderr',
            ],
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],

        'exception' => [
            'driver' => 'daily',
            'level' => 'debug',
            'days' => 5,
            'path' => storage_path('logs/exception.log'),
        ],

        'task' => [
            'driver' => 'daily',
            'level' => 'debug',
            'permission' => 0664,
            'days' => 5,
            'path' => storage_path('logs/task.log'),
        ],
    ],

];

b-14 切换到容器内项目根目录 执行以下命令

14-1、
    php composer.phar install &&
    php composer.phar dump-autoload &&
    chmod -R 777 sotrage &&
    chmod -R 777 bootstrap &&
    chown -R www-data:www-data storage &&
    chown -R www-data:www-data bootstrap/cache &&
    php artisan route:clear &&
    php artisan config:clear &&
    php artisan cache:clear

b-15 其他配置

15-1、根据 项目配置 config 下 yimq.php,micro.php 参数

b-16 配置虚拟域名

    b-16-1、windows  hosts 文件 记得映射 虚拟域名(与项目内 nginx.conf 中 server_name 一致)
    b-16-2、mac      /etc/resolver/test 文件 并写入 nameserver 127.0.0.1

b-17 切换到 workspace 目录下 重启容器并测试访问路由

    b-17-1、cd workspace && docker-composer restart
    b-17-2、http://{nginx.conf 中 server_name }/example/install   //例如:example.test/example/install 

img_3.png

18 通过 phpstorm 将 git 远程地址 更换成 新项目地址

img.png img_1.png

b-19 将以下内容 覆盖到 .gitignore

/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
/.idea
/.vscode
/.vagrant
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env
.phpunit.result.cache
_ide_helper.php
.phpstorm.meta.php
nginx.conf
.idea
img*
composer.phar
init.sh
give_log_permissions.sh

b-20 根目录 创建 ecosystem.config.js 并写入以下内容

    module.exports = {
        apps: [{
            name: 'audit-course',//队列名称
            script: 'artisan',
            user: 'www-data',
            cwd: '/apps',
            args: 'queue:work',//命令
            instances: 1,
            autorestart: true,
            watch: false,
            max_memory_restart: '1G',
            interpreter: 'php',
            env: {
                NODE_ENV: 'development'
            },
            env_production: {
                NODE_ENV: 'production'
            }
        }],
    };

b-21 example 框架 配置到 实际项目框架 需完成以下操作步骤

b-20-1、替换 Controllers 、Models、Services、Requests、Constants、Helpers、Filters 等目录下所有文件的命名空间,
b-20-2、替换 迁移文件 businesses,access_rights 加上表前缀
b-20-3、替换 数据填充 AccsessRightSeeder,BusinessSeeder 执行新增语句时的Model 命名空间更新
b-20-4、替换 Models 下 AccessRight,Business $table 加上表前缀
b-20-5、更新 .env 需求配置
b-20-6、替换 app/Providers/RouteServiceProvider.php 目录文件以及命名空间等
b-20-7、替换 nginx.conf
b-20-8、请注释  /app/Http/Kernel.php 下 ConvertEmptyStringsToNull 中间件
b-20-9、容器内项目根目录执行 composer dump-autoload
b-20-10、重启容器:docker-compose restart

---------- 方法b END 请前往 DEV-SPECIFICATION.md 阅读开发规范 --------

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/liuweiliang/example.git
git@gitee.com:liuweiliang/example.git
liuweiliang
example
example
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891