Define Constant in Laravel

November 17, 2020

There are several ways to define constants in Laravel

Create constant.php inside the config folder and add the following code

<?php

return [
    'HTTPSTATUS' => [
        'Informational_Continue' => '200',
        'Success_OK' => '200',
        'Redirection_MovedPermanently' => '301',
        'ClientError_BadRequest' => '400',
        'ServerError_InternalServerError' => '500',
    ]
];

You can access the the constant with following code

 Config::get('constant.HTTPSTATUS.ClientError_BadRequest')