PHPackages                             tusimo/eloquent-default - 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. [Database &amp; ORM](/categories/database)
4. /
5. tusimo/eloquent-default

ActiveLibrary[Database &amp; ORM](/categories/database)

tusimo/eloquent-default
=======================

set default value for eloquent

v0.1(8y ago)112MITPHP

Since Feb 12Pushed 8y agoCompare

[ Source](https://github.com/tusimo/eloquent-default)[ Packagist](https://packagist.org/packages/tusimo/eloquent-default)[ Docs](https://github.com/tusimo/laravel-default)[ RSS](/packages/tusimo-eloquent-default/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

EloquentDefault
===============

[](#eloquentdefault)

set the default value for [Laravel](https://laravel.com/)'s ORM. And define the column can save to database.

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

[](#installation)

Either [PHP](https://php.net) 5.6+ is required.

To get the latest version of EloquentDefault, simply require the project using [Composer](https://getcomposer.org):

```
$ composer require tusimo/eloquent-default
```

Instead, you may of course manually update your require block and run `composer update` if you so choose:

```
{
    "require": {
        "tusimo/eloquent-default": "^0.1"
    }
}
```

Usage
-----

[](#usage)

Within your eloquent model class add following line

```
use Tusimo\EloquentDefault\DefaultTrait;

class User extends Model {
    use DefaultTrait;

    /**
     * define the columns the table has
     * and define the default value saving to the database when attributes not set the column
     */
    protected $defaults = [
        '_id',
        'gender' => 1,
        'status' => 0,
        'deleted_at' => null,
    ];
    /**
     * when save attributes to database ,columns only defined in the defaults will save to database
     * default is false and we do nothing when the column is not in the database and this will throw
     * a exception when you using mysql or the data will saving to the database when you using mongo
     */
    protected $columnStrict = true;

    /**
     *Also you can define a method as `get*Default` to set a default value
     */
    preotected function getCustomDefault($custom)
    {
        return \Auth::isAdmin ? 'admin' : 'user';
    }
}
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Unknown

Total

1

Last Release

3012d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/05d5a0db1ead85cb05385aef0414b26e260d53a6d8e1cab0f74d884f5c872d39?d=identicon)[tusimo](/maintainers/tusimo)

---

Top Contributors

[![tusimo](https://avatars.githubusercontent.com/u/4344635?v=4)](https://github.com/tusimo "tusimo (3 commits)")

---

Tags

laraveldatabasemodeleloquentdefault

### Embed Badge

![Health badge](/badges/tusimo-eloquent-default/health.svg)

```
[![Health](https://phpackages.com/badges/tusimo-eloquent-default/health.svg)](https://phpackages.com/packages/tusimo-eloquent-default)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[friendsofcat/laravel-couchbase

A Couchbase based Eloquent model and Query builder for Laravel

1430.8k](/packages/friendsofcat-laravel-couchbase)

PHPackages © 2026

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