dev-master
9999999-devAllow to work with prefixes attributes name
MIT
The Requires
v0.0.1
0.0.1.0Allow to work with prefixes attributes name
MIT
The Requires
Wallogit.com
2017 © Pedro Peláez
Allow to work with prefixes attributes name
That package allows you to prefix attributes on your eloquent models., (*1)
composer require vluzrmos/eloquent-prefixes
You could use the model:, (*2)
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:, (*3)
$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:, (*4)
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 ]; }
Allow to work with prefixes attributes name
MIT
Allow to work with prefixes attributes name
MIT