global variable for all controller and views

后端 未结 16 2106
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:23

    A global variable for using in controllers; you can set in AppServiceProvider like this :

    public function boot()
    {
        $company=DB::table('company')->where('id',1)->first();
        config(['yourconfig.company' => $company]);
    }
    

    usage

    config('yourconfig.company');
    

提交回复
热议问题