Skip to content

Eager loading target relationship on ActionEvent for a non soft-deleted model throws an exception #5754

@marcmalha

Description

@marcmalha
  • Laravel Version: 10.9.0
  • Nova Version: 4.23.0
  • PHP Version: 8.1.17
  • Database Driver & Version: psql (PostgreSQL) 14.7 (Ubuntu 14.7-1.pgdg22.04+1)
  • Operating System and Version: ubuntu:22.04 docker image
  • Browser type and version: Chrome 114.0.5735.198
  • Reproduction Repository: https://github.com/###/###

Description:

The issue is related to the target(): morphTo relationship on the ActionEvent object.
The relationship implementation assumes that the target model has a SoftDeletes trait, which in some cases it doesn't.
Trying to eager load a model that doesn't use the SoftDeletes trait will throw a BadMethodCallException with the following error message: Call to undefined method Illuminate\Database\Eloquent\Builder::withTrashed().

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

  • Run an action on a resource whose model is not soft deleted
  • Run a the following select query in a tinker session:
    ActionEvent::with('target')->where('actionable_type', (new NonSoftDeletedModel)->getMorphClass())->get()

Metadata

Metadata

Assignees

Labels

bugVerified bug by the Nova team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions