2016-04-28 119 views

回答

16

您可以在config文件夾中創建一個文件。例如

config 
|- constants.php 

裏面constants.php你可以定義你的全局變量

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | User Defined Variables 
    |-------------------------------------------------------------------------- 
    | 
    | This is a set of variables that are made specific to this application 
    | that are better placed here rather than in .env file. 
    | Use config('your_key') to get the values. 
    | 
    */ 

    'company_name' => env('COMPANY_NAME','Acme Inc'), 
    'company_email' => env('COMPANY_email','[email protected]'), 


]; 

您可以使用這兩個函數訪問這些變量:

Config::get('constants.company_name') 
config('constants.company_name') 

刀片,以及:

{{ config('constants.company_email') }} 
+0

如果例如I想要在單獨的表格上檢索其他用戶信息。我如何將集合存儲在全局變量中? –

+0

@KimCarlo:我不確定你在問什麼。你的意思是緩存用戶信息? –

+0

我不確定這個詞是什麼,但例如,我有一個'user_details'表,它有一個'user_id'的外鍵,並且我查詢'user_id'等於經過驗證的用戶的ID 。我想將查詢結果存儲在全局變量中,以便可以在所有模塊中訪問它。 –