spatie / laravel-schemaless-attributes

Add schemaless attributes to Eloquent models
https://spatie.be/en/opensource
MIT License
1.01k stars 58 forks source link

Rewrite package with Eloquent value object casting #78

Closed sebastiandedeyne closed 3 years ago

sebastiandedeyne commented 3 years ago

Now that Eloquent supports custom casts with value object casting, I believe we could vastly improve the API and flexibility of this package, and remove a bunch of code in the process.

This is the current readme example:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Spatie\SchemalessAttributes\SchemalessAttributes;

class TestModel extends Model
{
    // ...

    public $casts = [
        'extra_attributes' => 'array',
    ];

    public function getExtraAttributesAttribute(): SchemalessAttributes
    {
        return SchemalessAttributes::createForModel($this, 'extra_attributes');
    }

    public function scopeWithExtraAttributes(): Builder
    {
        return SchemalessAttributes::scopeWithSchemalessAttributes('extra_attributes');
    }

    // ...
}

With value object casting, it could look like this:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Spatie\SchemalessAttributes\SchemalessAttributes;

class TestModel extends Model
{
    // ...

    public $casts = [
        'extra_attributes' => SchemalessAttributes::class,
    ];

    // ...
}

This would be a substantial rewrite of the package. We probably won't be picking this up ourselves soon. If someone else wants to pick this up, please respond below!

This is a great issue for first-time contributors, if needed, I can provide additional guidance and do in-depth PR reviews in the process.

tanseercena commented 3 years ago

Hi,

I am ready to help you with this.

@sebastiandedeyne it will be great if you provide some PR process etc.

Thanks

al-mootasem commented 3 years ago

Would love this to be my very first contribution to open source! I have read the guidelines and curious to know how the process goes?

patinthehat commented 3 years ago

I'll take this on, as it will give me the opportunity to also do the PHP 8 only upgrade.

sebastiandedeyne commented 3 years ago

Thanks for the offers for help, looks like this was taken care of before I even got back 😅