-
Notifications
You must be signed in to change notification settings - Fork 63
Respect custom morph types #190
base: develop
Are you sure you want to change the base?
Conversation
@sandervanhooft in case you consider this PR, there should be a additional 2.x branch. I can add a UPGRADE file if necessary to mention that the data in the tables have to be updated if morph maps are in use. |
Hi @mmachatschek , Can you elaborate on what issue this is solving / feature this is adding? Haven't worked with MorphMaps before. |
@sandervanhooft Let's say you set the following configuration in Laravel: use Illuminate\Database\Eloquent\Relations\Relation;
Relation::morphMap([
'user' => \App\User::class,
]); This tells Eloquent to use the string In cashier-mollie you set the When querying these tables with Eloquent, you wont be able to find any entries because the A even better solution would be to not directly e.g. use App\User;
use Laravel\Cashier\Credit\Credit;
$owner = User::first();
$credit = new Credit([
'currency' => 'EUR',
'value' => 1000
]);
$credit->owner()->associate($owner);
$credit->save(); Custom morph types https://laravel.com/docs/master/eloquent-relationships#custom-polymorphic-types |
Simply put, the problem that the MorphMap solves the problem is the pain of refactoring model names (or namespaces) when using morph relationships. Example: I move my With a MorphMap, I can change Relation::morphMap([
'user' => \App\User::class,
]); to Relation::morphMap([
'user' => \App\Models\User::class,
]); and then everything will work again (of course, granted that I used the MorphMap when the |
@sandervanhooft If you want me to pick up the work mentioned here, let me know:
|
Can you explain why you think this is better? I only see two DB calls instead of one? |
This adds support for custom morph map settings in Laravel.
Could be something for v2 release.
Currently, the morphed types are saved with the FQDN.
Now a configuration like this:
..will result in database entries like, e.g order_items: