Laravel

Constants

Example

First you have to create a file constants.php and it is a good practice to create this file inside app/config/ folder. You can also add constants.php file in compose.json file.

Example File:

app/config/constants.php

Array based constants inside the file:

return [
    'CONSTANT' => 'This is my first constant.'
];

And you can get this constant by including the facade Config :

use Illuminate\Support\Facades\Config;

Then get the value by constant name CONSTANT like below :

echo Config::get('constants.CONSTANT');

And the result would be the value :

This is my first constant.


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow