Skip to content

Makes Eloquent models use singular (rather than plural) table names by default.

License

Notifications You must be signed in to change notification settings

actionable-co/eloquent-singular-table-names

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eloquent singular table names

Makes Eloquent models use singular (rather than plural) table names by default.

Usage

Simple apply the trait to your Eloquent model:

namespace App;

use Illuminate\Database\Eloquent\Model;
use MartinBean\Database\Eloquent\SingularTableName;

class User extends Model
{
    use SingularTableName;
}

The default table name will be user now, rather than users.

If you wish to use singular table names for all of your models, then you can create an abstract class that implements the trait, and have all of your models extend that class:

namespace App;

use Illuminate\Database\Eloquent\Model;
use MartinBean\Database\Eloquent\SingularTableName;

abstract class SingularModel extends Model
{
    use SingularTableName;
}
namespace App;

class User extends SingularModel
{
    // No need to implement trait
}

About

Makes Eloquent models use singular (rather than plural) table names by default.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%