2017 © Pedro Peláez
 

library eloquent-prefixes

Allow to work with prefixes attributes name

image

vluzrmos/eloquent-prefixes

Allow to work with prefixes attributes name

  • Saturday, February 6, 2016
  • by vluzrmos
  • Repository
  • 1 Watchers
  • 1 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Eloquent Prefixes

That package allows you to prefix attributes on your eloquent models., (*1)

Installation

composer require vluzrmos/eloquent-prefixes

Usage

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 ]; }

TODO

  • [ ] Works with Query Builders
  • [x] Works with Model Attributes (Automatic Accessors and Mutators)

The Versions

06/02 2016

dev-master

9999999-dev

Allow to work with prefixes attributes name

  Sources   Download

MIT

The Requires

 

06/02 2016

v0.0.1

0.0.1.0

Allow to work with prefixes attributes name

  Sources   Download

MIT

The Requires