Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

[Proposal] Support custom casting types #1188

Closed
rentalhost opened this issue May 29, 2018 · 3 comments
Closed

[Proposal] Support custom casting types #1188

rentalhost opened this issue May 29, 2018 · 3 comments

Comments

@rentalhost
Copy link

Currently Eloquent casting supports the most common types: int (integer), float (double, real), string, bool (boolean), object, array (json), collection, date, datetime (custom_datetime) and timestamp.

Although it can solve most of the problems, I believe it is feasible to implement a casting interface to expand this concept, making possible cast to anything else (since it implements a specific interface).

Something like:

interface CastingInterface {
    public function setter(...); // Called before persist data.
    public function getter(...); // Called before read persited data.
}

So you can implements this interface to a casting class, and handle without need implements an acessor or mutator.

The use should be like:

protected $casts = [
    'pallete' => PalleteCasting::class
];
@tomschlick
Copy link

This has been attempted a few times with:

laravel/framework#13706

laravel/framework#18106

and a few others.

@tomschlick
Copy link

@rentalhost FYI, that wasn't a call to close this issue. Just a reference to those previous discussions / PRs so it could learn from them. This is a much needed change but so far no one has come up with a mergeable solution.

@rentalhost
Copy link
Author

Oh, sorry. Actually I close because that it have a long discussion with PR. So I need read it first to understand if I can keep it open. Thanks you for reply! :D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants