“Share” any kind of data to all views within a controller in Laravel framework

public function __construct()
    {
        //Get from Database some options, for example the header and title of your site
        $site_options = Admin::where('status','active')->first();
        $header = $site_options->site_header;
        $title = $site_options->site_title;

         $data = [
                'site_header'=>$header,
                'site_title'=>$title
                 ];

        view()->share('data_view',$data);
    }

for example set header and title from an active options set.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fork us on GitHub