Laravel 5.8 Global Blade view variable

Today, We want to share with you Laravel 5.8 Global Blade view variable.In this post we will show you laravel global variable for all controller, hear for Sharing Data Between Views Using Laravel View Composers we will give you demo and example for implement.In this post, we will learn about Laravel 5 – global Blade view variable available in all templates with an example.

Laravel 5.8 Global Blade view variable

There are the Following The simple About Laravel 5.8 Global Blade view variable Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel pass multiple variables to controller, so the Laravel 5.8 Pass Variables to Master Template for this example is following below.

Also Read :  Laravel passing multiple variables Across multiple pages

We can use simple view::share() like below source code:

<?php namespace App\Http\Controllers;

use View;

//We can create a BaseController:

class BaseController extends Controller {

    public $variants = "Product variants all available";

    public function __construct() {

       $website_title = "Welcome to pakainfo.com";


       View::share ( 'variants', $this->variants );
       View::share ( 'website_title', $website_title );
       View::share ( 'welcomemsg', 'I am Angularjs with Laravel Devlopers' );
       View::share ( 'employeedetails', ['name'=>'Jaydeep','address'=>'Gondaliya'] );
    }  

}

class HomeController extends BaseController {

    //if We have a simple call a constructor in other more controllers We need call constructor of main parent controller (i.e. root like BaseController) like so:

    public function __construct(){
       parent::__construct();
    }

    public function Index(){
      //All laravel variable will be available in blade views files
      return view('product');
    }

}

Web Programming Tutorials Example with Demo

Read :

Also Read :  Create Bootable USB Drive Steps - Bootable Pen Drive

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.8 Global Blade view variable.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of