PHPackages                             adev/lrc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. adev/lrc

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

adev/lrc
========

A package to generate column constants for Laravel models

v2.0.3(1y ago)145MITPHPPHP &gt;=7.4

Since Dec 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/adilelkhalloufi/lrc)[ Packagist](https://packagist.org/packages/adev/lrc)[ Docs](https://adev.ma/)[ RSS](/packages/adev-lrc/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

adev\\lrc
=========

[](#adevlrc)

A Laravel package to generate column constants for your models based on their table schema. This helps improve consistency and readability in your application, especially when referring to table columns in your code.

Features
--------

[](#features)

Automatically generates constants for each column in your model. Generates a TABLE\_NAME constant for each model. Easy to use in migrations, controllers, and other parts of your application.

Installation
------------

[](#installation)

You can install the package via Composer. Run the following command in your Laravel project:

```
composer require adev/lrc
```

Once installed, the package will automatically register the Artisan command.

Usage
-----

[](#usage)

After the package is installed, you can use the make:constants Artisan command to generate column constants for a given model.

Generate Constants for a Single Model To generate constants for a specific model, run:

```
php artisan make:constants User
```

This will generate the following constants in your User model (assuming your model is located in app/Models/User.php):

```
public const TABLE_NAME = 'users';
public const COL_ID = 'id';
public const COL_NAME = 'name';
public const COL_EMAIL = 'email';
// and so on for each column in the 'users' table
```

Generate Constants for All Models
---------------------------------

[](#generate-constants-for-all-models)

To generate constants for all models in your app/Models directory, run:

```
php artisan make:constants all
```

This will loop through all models and generate column constants for each one.

How to Use the Constants
------------------------

[](#how-to-use-the-constants)

Once the constants are generated in your models, you can easily use them throughout your application, for example in migrations, controllers, or queries. Here's how you can utilize these constants:

Generate Constants with Fillable
================================

[](#generate-constants-with-fillable)

If you want to include a $fillable property in the model using the generated constants, use the --fillable option:

```
php artisan make:constants User --fillable
```

Delete Constants
----------------

[](#delete-constants)

To delete previously generated constants for a specific model, use the --delete option:

```
php artisan make:constants {model} --delete
```

For example, to delete constants for the User model:

```
php artisan make:constants User --delete
```

To delete constants for all models, use:

```
php artisan make:constants all --delete
```

1. In Migrations
----------------

[](#1-in-migrations)

When creating or modifying database tables in migrations, you can reference the constants instead of hardcoding column names.

```
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
   public function up()
   {
           Schema::create('users', function (Blueprint $table) {
           $table->id();
           $table->string('name')->nullable();

           $table->foreignId('family_id')
           ->nullable()
           ->constrained(Family::TABLE_NAME);
           $table->timestamps();
       });
   }

   public function down()
   {
       Schema::dropIfExists(User::TABLE_NAME);
   }
}
```

2. In Controllers
-----------------

[](#2-in-controllers)

Using constants makes it easier to refer to column names in your queries or when manipulating data in controllers.

```
use App\Models\User;

class UserController extends Controller
{
    public function show($id)
    {
        $user = User::where(User::COL_ID, $id)->first();

        if (!$user) {
            return response()->json(['message' => 'User not found'], 404);
        }

        return response()->json($user);
    }

    public function update(Request $request, $id)
    {
        $user = User::where(User::COL_ID, $id)->first();

        if ($user) {
            $user->update([
                User::COL_NAME => $request->name,
                User::COL_EMAIL => $request->email,
            ]);
        }

        return response()->json($user);
    }
}
```

3. In Seeders
-------------

[](#3-in-seeders)

You can also use the constants in seeders to populate the database.

```
use App\Models\User;

class UserSeeder extends Seeder
{
    public function run()
    {
        User::create([
            User::COL_NAME => 'John Doe',
            User::COL_EMAIL => 'john.doe@example.com',
        ]);
    }
}
```

4. In Queries
-------------

[](#4-in-queries)

You can use the constants when building queries, which improves readability and reduces the chance of errors due to typos.

```
use App\Models\User;

// Using constants for column names
$users = User::where(User::COL_NAME, 'like', '%John%')
             ->orderBy(User::COL_EMAIL)
             ->get();
```

Benefits of Using Constants
---------------------------

[](#benefits-of-using-constants)

Prevents Hardcoding: Instead of hardcoding column names as strings, you can use the constants, which improves maintainability and reduces the chances of errors caused by typos. Improves Readability: Using constants like User::COL\_NAME makes it clear that you're referring to a database column, not just any string. Easy Refactoring: If you ever change the column name in the database or the model, you only need to update it in the constants, rather than in every place where the column is referenced in the code. Configuration (Optional) If you'd like to customize the behavior of the package (such as the location of your models or other settings), you can publish the configuration file.

```
php artisan vendor:publish --provider="LRC\Providers\CommandConstantsServiceProvider" --tag="config"
```

This will publish the command\_constants.php file to your config/ directory, where you can adjust the settings.

License
-------

[](#license)

This package is open-source and available under the MIT License.

Example: Complete Workflow
==========================

[](#example-complete-workflow)

Let's walk through a complete example where you create a User model, generate column constants, and use them in a migration, controller, and seeder.

1 Create the Model:
-------------------

[](#1-create-the-model)

If you haven't created the model yet, run:

```
php artisan make:model User
```

This will generate a model file at app/Models/User.php.

2 Run the Command to Generate Constants:
----------------------------------------

[](#2-run-the-command-to-generate-constants)

After the User model is generated, run the command to generate constants:

```
php artisan make:constants User
```

This will add constants like COL\_NAME, COL\_EMAIL, and TABLE\_NAME in the User model.

3 Use Constants in the Migration:
---------------------------------

[](#3-use-constants-in-the-migration)

Create a migration to create the users table (if not already done):

```
php artisan make:migration create_users_table
```

In the generated migration, use the constants as shown earlier.

4 Use Constants in the Controller:
----------------------------------

[](#4-use-constants-in-the-controller)

Now, in the UserController, use these constants to refer to the columns.

5 Use Constants in the Seeder:
------------------------------

[](#5-use-constants-in-the-seeder)

You can populate the users table in your UserSeeder using the constants.

Conclusion
==========

[](#conclusion)

By using this package, you can improve the maintainability and readability of your Laravel project by generating and using constants for column names in your models. It ensures that column names are consistent across your application, making it easier to manage as your project grows.

Contact, Support, or Donations
==============================

[](#contact-support-or-donations)

If you would like to contact me for any reason, including support, questions, or contributions to this project, feel free to reach out via:

Email: \[\] GitHub:

Donations
=========

[](#donations)

If you want to support the development of this project, you can make a donation via the following options:

[PayPal](https://www.paypal.com/donate/?hosted_button_id=2MDDDBX75Z3UQ)Any donation is appreciated and will go toward improving this project.

Contributing I welcome contributions! If you'd like to contribute to the project, please follow the instructions in the Contributing Guidelines or simply open an issue or pull request.

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

6

Last Release

533d ago

Major Versions

v1.0.2 → v2.0.02025-01-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e787f5c6aba95910ae01b38423583773f94a5ec9959726fa5d57302bb6a4ba0?d=identicon)[adilelkhalloufi](/maintainers/adilelkhalloufi)

---

Top Contributors

[![adilelkhalloufi](https://avatars.githubusercontent.com/u/61150985?v=4)](https://github.com/adilelkhalloufi "adilelkhalloufi (36 commits)")

---

Tags

constantscolumns

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/adev-lrc/health.svg)

```
[![Health](https://phpackages.com/badges/adev-lrc/health.svg)](https://phpackages.com/packages/adev-lrc)
```

###  Alternatives

[rexlabs/enum

Enumeration (enum) implementation for PHP

47502.6k2](/packages/rexlabs-enum)[php-stubs/wordpress-globals

Global variables and global constants from WordPress core.

13847.8k20](/packages/php-stubs-wordpress-globals)[madeyourday/contao-rocksolid-columns

Arrange your content elements in responsive columns

10119.1k2](/packages/madeyourday-contao-rocksolid-columns)[optimistdigital/nova-resizable

Simple Laravel Nova tool to enable column resizing

1819.5k](/packages/optimistdigital-nova-resizable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
