Laravel 5.8 Global Blade view variable

Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

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.

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 :

Read Also:  Passing data to views from routes in Laravel

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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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