global variable for all controller and views

后端 未结 16 2115
Happy的楠姐
Happy的楠姐 2020-11-27 15:54

In Laravel I have a table settings and i have fetched complete data from the table in the BaseController, as following

public function __construct() 
{
             


        
16条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 16:04

    In file - \vendor\autoload.php, define your gobals variable as follows, should be in the topmost line.

    $global_variable = "Some value";//the global variable
    

    Access that global variable anywhere as :-

    $GLOBALS['global_variable'];
    

    Enjoy :)

提交回复
热议问题