美文网首页
构建一个 Laravel composer 包

构建一个 Laravel composer 包

作者: 会飞一下 | 来源:发表于2019-06-19 15:15 被阅读0次
    1. 新建 composer.json 文件
    {
        "name": "company-name/project-name",
        "type": "project",
        "autoload": {
            "files": [
                "src/Helpers/helpers.php"
            ],
            "psr-4": {
                "project-namespace\\": "src/"
            }
        },
        "autoload-dev": {
            "psr-4": {
                "project-test-namespace\\": "tests/"
            }
        },
        "require-dev": {
            "phpunit/phpunit": "~5.7"
        }
    }
    
    1. 新建 ./src/ProjectNameProvider.php
    namespace ProjectNamespace;
    
    use Illuminate\Support\ServiceProvider;
    
    class ProjectNameProvider extends ServiceProvider
    {
        public function boot()
        {
            $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
            if ($this->app->runningInConsole()) {
                $this->commands([
                    \ProjectNamespace\Commands\ProjectGenerate::class,
                ]);
            }
            $this->loadViewsFrom(__DIR__.'/views', 'projectView');
        }
    
        public function register()
        {
            $provides = [
                'ProjectNamespace\Http\RouteServiceProvider',
            ];
            foreach ($provides as $provider) {
                $this->app->register($provider);
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:构建一个 Laravel composer 包

          本文链接:https://www.haomeiwen.com/subject/wqdkqctx.html