How to Define Constant Variable in Laravel 7/6?

How to Define Constant Variable in Laravel 7/6?

In this post we will give you information about How to Define Constant Variable in Laravel 7/6?. Hear we will give you detail about How to Define Constant Variable in Laravel 7/6?And how to use it also give you demo for it if it is necessary.

In this tutorial, we will learn how to define constant variable in laravel 7/6 application. we can easily create laravel 7/6 constants variable. you can define constants variable with string value, integer value, array value and you can access for all controller, all views, all blade files, middleware too in laravel 7/6 using config.

We must be require to define some global value for application like number of pagination records, user type, site url etc. if you are working with small project then i will suggest to create global config file for define constants variable.

In this example we will create one global config file will all define default variable with values. so you can use that variable from anywhere in project. you can also check bellow screen shot for file location.

Create Config File

We need to create global.php config file with constants variable value and you can also define array value like as bellow:



return [

'pagination_records' => 10,

'user_type' => ['User', 'Admin'],



Use Constant Variable

You can easily get value using config() helper. you can see bellow example:


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




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




I hope it can help you….

Hope this code and post will helped you for implement How to Define Constant Variable in Laravel 7/6?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

1  +  8  =  

We accept paid advance and paid guest Posting on our Site : Contact US