troelskn / laravel-fillable-relations

Provides HasFillableRelations trait to Eloquent models
64 stars 23 forks source link

Question: Does this work with MorphMany? #12

Closed DanJFletcher closed 5 years ago

DanJFletcher commented 5 years ago

I noticed a method suggesting that MorphTo might work but didn't see any examples in the tests that suggest polymorphic relations are actually working.

Was hoping to be able to do something like:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use LaravelFillableRelations\Eloquent\Concerns\HasFillableRelations;

class Forum extends Model
{
    use HasFillableRelations;

    protected $fillable_relations = ['title'];

    public function title()
    {
        return $this->morphMany(TitleTranslation::class, 'translatable');
    }
}

And the inverse:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class TitleTranslation extends Model
{
    protected $fillable = [
        'lang_id',
        'text',
        'translatable_id',
    ];

    public function translatable()
    {
        return $this->morphTo();
    }
}

Which I understand is a little tricky to support. Just curious if there's any headway on supporting polymorphic fillables like this or if you need any help.

Thanks for making this by the way!

troelskn commented 5 years ago

Hi Dan.

It's been a while since I touched the code, since I'm not currently actively using Laravel, but it looks to me like that might just be a question of reusing the logic for HasMany. I'll make a quick test and see.

troelskn commented 5 years ago

That turned out well enough. I'll merge it to master. Let me know if it works out for you?