How to Define Constant Variable in Laravel?

In this post, I am going to explain “how to define constant variable in laravel”.  we can create any type constant variable like array, string, Integer etc.

And can access any where in application like view, Controller, middle-ware etc.
Many times we require to define some global value for application like user type, site URL, success message, error message etc.

In this post we will create one global config file and define all default variable with values in created file. After that we can use that variable from anywhere in project.

Step 1:- Create Config File

first we need to create a file in config folder and then define constant variable and value in that file.
Create global.php file in config folder and paste below code.

Step:2 ) How to use Constant Variable, we can easly get config value using config() helper like:

I hope you might have understood it properly, keep reading our other blog posts for more coding tricks.


Add a Comment

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