Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

I'm not beyond bribing someone for help... For the first person to solve this, you get a special animated GIF!

0
Solution

[SOLVED] I ended up just using the morphClass and an alias to match the morphMany, instead of the Image->getReferenceTypeAttribute() method. It turns out the 502 error was the morphMany working, which triggered another issue happening down the line (I had removed to simplify the code). Here are the changes that were made to the above code examples.

UserCharacter Model (7/8)

class UserCharacter extends Model
{
    protected $morphClass = 'UserCharater' // was cosplayheroes\UserCharacter.  The 502 error was actually the morphMany working, but other code issues down the line.

    ....
}

Image Model (8/8)

class Image extends Model
{
    ...
    
    //removed protected $types = [ ... ];

    ....

    //removed public function getReferenceTypeAttribute($type) { ... }

}

config\app.php (9/8)

    ... 

    'aliases' => [
        ...
        'UserCharacter' => 'app\UserCharacter', /* added this alias so morphClass and the MySQL reference_type would match */
    ],

And, of course, I can't forget that animated GIF reward I promised myself... Winning all the code

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mlusas mlusas Joined 19 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.