DEV Community

Discussion on: Alternatives to using a constants.php file in your Laravel project

tradjick profile image

I use all of the above depending on usage and context. Regarding the db, I use both in class constants and enum fields within the model classes and migrations. I will have something like:

class Terminal extends Model
const STATE_REGISTERED='registered';
const STATE_UPDATE='update';
const STATE_LOCKED='locked';

and within the migration:

The above means there is a singular authoritative source, that is detectable by the IDE, is contextual within the model, reduces record size for storage, speeds searches, and is enforced on the data storage level.

The only caveat with this technique is the migration changes if you change the authoritative class constant.