# Laravel Cpanel vendor共用 ###### tags: `cpanel` ## 說明 各別專案共用相同的vendor但本案中的自己寫controllers、model... 要取代autoload_static.php中的classMap各別使用 ## 取得專案自己所撰寫APP開頭的classMap ### 開啟<span style="color:red">此專案的</span>vendor/composer/autoload_static.php取得中的classMap此專案自己的class ![](https://i.imgur.com/6SCQ7P7.png) ### bootstrap資料夾內修改app.php #### <span style="color:red">主要是將自己的class新增至classMap陣列當中,若沒有這麼做autoload_static.php會找不到你自己所新增撰寫的class位置 ![](https://i.imgur.com/M6x29i8.png) ![](https://i.imgur.com/d71OQX7.png) ``` <?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. | */ $autoload = new Composer\Autoload\ClassLoader(); $autoload->addPsr4('App\\', "../app/"); $autoload->register(); $baseDir = '/home/uikchen/public_html/nhh/';// 重要需要設定底下class對應位置(每個專案都不同) $loader = require __DIR__ . '/../../vendor/autoload.php'; $loader->addClassMap([ 'App\\Console\\Kernel' => $baseDir . 'app/Console/Kernel.php', 'App\\Exceptions\\Handler' => $baseDir . 'app/Exceptions/Handler.php', 'App\\Http\\Controllers\\AccountController' => $baseDir . 'app/Http/Controllers/AccountController.php', 'App\\Http\\Controllers\\Controller' => $baseDir . 'app/Http/Controllers/Controller.php', 'App\\Http\\Controllers\\GAController' => $baseDir . 'app/Http/Controllers/GAController.php', 'App\\Http\\Controllers\\IndexController' => $baseDir . 'app/Http/Controllers/IndexController.php', 'App\\Http\\Controllers\\LoginController' => $baseDir . 'app/Http/Controllers/LoginController.php', 'App\\Http\\Controllers\\MailController' => $baseDir . 'app/Http/Controllers/MailController.php', 'App\\Http\\Controllers\\ProductController' => $baseDir . 'app/Http/Controllers/ProductController.php', 'App\\Http\\Kernel' => $baseDir . 'app/Http/Kernel.php', 'App\\Http\\Middleware\\Authenticate' => $baseDir . 'app/Http/Middleware/Authenticate.php', 'App\\Http\\Middleware\\EncryptCookies' => $baseDir . 'app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\PreventRequestsDuringMaintenance' => $baseDir . 'app/Http/Middleware/PreventRequestsDuringMaintenance.php', 'App\\Http\\Middleware\\RedirectIfAuthenticated' => $baseDir . 'app/Http/Middleware/RedirectIfAuthenticated.php', 'App\\Http\\Middleware\\TrimStrings' => $baseDir . 'app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustHosts' => $baseDir . 'app/Http/Middleware/TrustHosts.php', 'App\\Http\\Middleware\\TrustProxies' => $baseDir . 'app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\UserAuthentication' => $baseDir . 'app/Http/Middleware/UserAuthentication.php', 'App\\Http\\Middleware\\VerifyCsrfToken' => $baseDir . 'app/Http/Middleware/VerifyCsrfToken.php', 'App\\Mail\\MyTestMail' => $baseDir . 'app/Mail/MyTestMail.php', 'App\\Models\\Product' => $baseDir . 'app/Models/Product.php', 'App\\Models\\Profile' => $baseDir . 'app/Models/Profile.php', 'App\\Models\\User' => $baseDir . 'app/Models/User.php', 'App\\Providers\\AppServiceProvider' => $baseDir . 'app/Providers/AppServiceProvider.php', 'App\\Providers\\AuthServiceProvider' => $baseDir . 'app/Providers/AuthServiceProvider.php', 'App\\Providers\\BroadcastServiceProvider' => $baseDir . 'app/Providers/BroadcastServiceProvider.php', 'App\\Providers\\ComposerServiceProvider' => $baseDir . 'app/Providers/ComposerServiceProvider.php', 'App\\Providers\\EventServiceProvider' => $baseDir . 'app/Providers/EventServiceProvider.php', 'App\\Providers\\RouteServiceProvider' => $baseDir . 'app/Providers/RouteServiceProvider.php', 'App\\Repository\\ProductRepository' => $baseDir . 'app/Repository/ProductRepository.php', 'App\\Services\\AccountServices' => $baseDir . 'app/Services/AccountServices.php', 'App\\Services\\Account\\Login' => $baseDir . 'app/Services/Account/Login.php', 'App\\Services\\ImageCreate' => $baseDir . 'app/Services/ImageCreate.php', 'App\\Services\\ProductService' => $baseDir . 'app/Services/ProductService.php', 'App\\Services\\ProfileServices' => $baseDir . 'app/Services/ProfileServices.php', ]); $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, App\Exceptions\Handler::class ); /* |-------------------------------------------------------------------------- | 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; ``` ## 將共用的vendor放在所有專案的最外層 ![](https://i.imgur.com/gbTCYgS.png) ## 修改public/index.php ![](https://i.imgur.com/AjvgN2U.png) ## 完成~~~ # <span style="color:red">但注意vender這包一定要包含所有專案的套件否則有缺少的會打不開,好處是會提醒有缺套再自己新增進去瞜(建議可以多一個資料夾放composer.json把所有套件統一管理)</span>