Constants play important role and many times you need some globally defined constants which can be use throughout the project. Laravel is most popular and full of features framework in PHP. It is easy in laravel to define constant and use in whole project.

Steps to create constant

STEP-1 Create a new file named constants.php inside config folder.

STEP-2 In this file you create array and add any number of elements. Here is an example of order stage

return [
    'ORDER_STAGES' => array(
        'ready'=>'Ready to Ship',

That’s it.


Here Variable_Name is array element defined in constant.php file inside config folder.

How to use

These array defined in constant.php can be use throughout the project in controller and view (blade files)

To use in controller – config(“constants.ORDER_STAGES”)
To use in Blade View – {{ config(‘constants.ORDER_STAGES‘) }}

This is an easy way to use global array variable as constant


Leave a Reply

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