laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.55k stars 11.03k forks source link

[Proposal] Decouple mutators / attribute casting from the Eloquent ORM #16377

Closed andrzejkupczyk closed 8 years ago

andrzejkupczyk commented 8 years ago

Wouldn't be great to encapsulate the attributes manipulation? That could be very useful eg. in the Request class. Regarding casting I thought of something as simple as:

abstract class Model implements ArrayAccess, Arrayable, Castable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable
{
    use CastableTrait;
    …
}
class Request extends SymfonyRequest implements Arrayable, ArrayAccess, Castable
{
    use CastableTrait, Macroable;
    …
}

In combination with custom casting discussed in https://github.com/laravel/framework/pull/16305 and https://github.com/laravel/framework/pull/13706 it could be a very powerfull and yet a clean solution. Another approach could be a Processor/Transformer implementation (this is just a basic idea inspired by the need to encapsulate request data processing):

GrahamCampbell commented 8 years ago

Thanks. Please open an issue on the internals repo to discuss this. We strictly only deal with isolated bug reports here.