How to Declare Global Variable in Laravel 6?

Today, We want to share with you How to Declare Global Variable in Laravel 6?.In this post we will show you laravel 6 set global variable in middleware, hear for Laravel 6 define global constants Config php file we will give you demo and example for implement.In this post, we will learn about how to make a global variable in laravel 6 controller with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

How to Declare Global Variable in Laravel 6?

There are the Following The simple About How to Define Global Variable in Laravel 6.0 Application Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to define Global or constant Variables in Laravel 6?, so the Define Global Variable in Laravel 6.0 is used for this example is following below.

Step 1: Create a Laravel 6 Global Config File


	return [
	    'total_products' => 555,
	    'product_type' => ['Simple', 'Grouped', 'Varible'],

Step 2: Use Laravel 6 Global Variable

We can simple way to get/fetch value using config() main laravel global helper. we can see bellow laravel Route example:


Route::get('get-product-type', function()

Route::get('get-product-type', function()

global variable for all controller and views

class BaseController extends \Controller

    protected $product_type;

    public function __construct() 
        // Fetch the All Product object
        $this->product_type = Product::all();
        View::share('product_type', $this->product_type);


Web Programming Tutorials Example with Demo

Read :


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

I hope you get an idea about super global variable in laravel 6.
I would like to have feedback on my 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.

Related FAQ

Here are some more FAQ related to this Article:

  1.   how to create registration form in wordpress without plugin?
  2.   jQuery Validation Email Mobile password Regular Expression
  3.   Responsive image gallery with thumbnail carousel Slider wordpress plugin
  4.   PayPal Referral & Earn 2020: $100 Referral Link | Earn Upto $100
  5.   How to declare a global variable in Laravel 5.8?
  6.   open new tab in reactjs Example Tutorial
  7.   Angular 6 HTTP Get Method with Example
  8.   Laravel 6 Define Global Constants Config PHP file
  9.   Global variable in laravel controller Example
  10.   PHP Jquery Ajax Upload Multiple Images with Preview

Leave a Reply

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