vluzrmos/eloquent-prefixes
Composer 安装命令:
composer require vluzrmos/eloquent-prefixes
包简介
Allow to work with prefixes attributes name
README 文档
README
That package allows you to prefix attributes on your eloquent models.
Installation
composer require vluzrmos/eloquent-prefixes
Usage
You could use the model:
use Vluzrmos\Database\Eloquent\ModelWithPrefixedAttributes as Model; class MyModel extends Model { /** * A string that should be used to prefix attributes. */ protected $attributesPrefix = "my_"; /** * Array of attributes to prefix */ protected $attributesToPrefix = [ 'name', 'email' ]; protected $fillable = [ 'name', 'email', // 'my_name', //only if you need it // 'my_email' //only if you need it ]; }
And then you can use:
$model = MyModel::first();
$model->name; //same of $model->my_name;
$model->name = "Vluzrmos"; //same of $model->my_name = "Vluzrmos";
MyModel::create([
'name' => 'Vagner do Carmo',
'email' => 'my_email@gmail.com'
]);
// its the same of
MyModel::create([
'my_name' => 'Vagner do Carmo',
'my_email' => 'my_email@gmail.com'
]);
//Note:: that should be on your fillable array.
You could use the Trait too, that works the same way:
ues Illuminate\Database\Eloquent\Model; use Vluzrmos\Database\Eloquent\PrefixesAttributes; class MyModel extends Model { use PrefixesAttributes; /** * A string that should be used to prefix attributes. */ protected $attributesPrefix = "my_"; /** * Array of attributes to prefix */ protected $attributesToPrefix = [ 'name', 'email' ]; protected $fillable = [ 'name', 'email', // 'my_name', //only if you need it // 'my_email' //only if you need it ]; }
TODO
- Works with Query Builders
- Works with Model Attributes (Automatic Accessors and Mutators)
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-06