Skip to content

MorphToMany Accessing Blank Models? #3746

@jjjrmy

Description

@jjjrmy
  • Laravel Version: 8
  • Nova Version: 3.31
  • PHP Version: 8
  • Database Driver & Version: MySQL

Description:

If you add a Ray debug to the relationship method, the API request is returning blank models as shown below when accessing a Post resource.

class Post extends Model {
  public function tags() {
     ray(request()->url(), $this)->label(__FUNCTION__);
     return $this->morphToMany(Tag::class, 'taggable');
  }
}

In my example this Post has 3 Tags, and it seem to be outputting 3 blank Post models in the debug output.
This is causing me problems and doesn't seem right.
Ray Output

Why is this happening and is there a way to prevent it?

Detailed steps to reproduce the issue on a fresh Nova installation:

1.) Follow this structure for creating Laravel & Nova Models:
https://laravel.com/docs/8.x/eloquent-relationships#many-to-many-polymorphic-relations
2.) Create / Seed the Tags and Posts + Videos
3.) Navigate to a Post

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions