簡體   English   中英

Laravel應用程序引導設置選項

[英]Laravel application bootstrap setting options

我正在使用第三方庫開發各種輔助功能的Laravel應用。

該庫的行為方式取決於環境(開發,測試,生產)。

我想根據Laravel .env設置的值來設置庫的調試設置,並且我認為最好的設置是在bootstrap/app.php文件中。 所以我在返回$app之前嘗試這樣的事情:

MyCustomLibrary::set_debug(config('app.debug'));
return $app;

這將引發錯誤ReflectionException: Class config does not exist

如果不在bootstrap/app.php ,該在哪里設置呢? 我會使用其他語法嗎?

我認為在引導方法的AppServiceProvider內部將是一個不錯的地方。

use MyCustomLibrary;

class AppServiceProvider extends ServiceProvider 
{
    public function boot()
    {
        MyCustomLibrary::set_debug(config('app.debug'));
    }
    ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM