Not compatible with enforceMorphMap integers
olavski opened this issue · 2 comments
Lemon Squeezy for Laravel Version
1.1.0
Laravel Version
10.16.1
PHP Version
8.1.12
Description
First, thank you for creating and maintaining this package!
My app uses morph-maps and I was getting "The checkout_data.custom.billable_type must be a string." when I used integers in the morph map:
Relation::enforceMorphMap([
1 => User::class,
//...
]);
Parts of my application have millions of rows so using tinyint for class types greatly increases performance.
I got it to work by reverting back to using strings, but it could be useful if also integers for billable_types were also allowed.
Steps To Reproduce
Set up morph-map
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Relation::enforceMorphMap([
1 => User::class,
]);
}
}
I was working on a new project and ran into the same issue, but see I've already reported it.
I'm currently using lemonsqueezy/laravel
v1.4.0
The workaround I'm using is this:
Relation::enforceMorphMap([
User::class=> User::class, // for lemonsqueezy compatibility
1 => User::class, // for the rest of the application
]);
As I have found a workaround, it is not urgent to fix it but it would be good if future versions could support enforceMorphMap
.
Hi @olavski. Sorry for the very late reply here.
enforceMorphMap
isn't meant to be used with integers as keys, only strings. This isn't an issue of this package but a Laravel thing. Please see its docs here: https://laravel.com/docs/eloquent-relationships#custom-polymorphic-types