Level 5
Check if the types you are using are Nova resources and not models.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When defining one to many polymorphic relations on Laravel Nova resource it throws an exception Call to undefined method singularLabel() or Call to undefined method uriKey() on model.
If i define the two static methods on the models what should the the returned type be.
Below is the related models and the resource.
Eloquent Models:
class QuestionDiagram extends Model
{
public function diagramable()
{
return $this->morphTo();
}
}
class Preamble extends Model
{
public function diagrams()
{
return $this->morphMany(QuestionDiagram::class, 'diagramable');
}
public static function singularLabel()
{
// what should be returned
}
public static function uriKey()
{
// what should be returned
}
}
class Question extends Model
{
public function diagrams()
{
return $this->morphMany(QuestionDiagram::class, 'diagramable');
}
public static function singularLabel()
{
// what should be returned
}
public static function uriKey()
{
// what should be returned
}
}
Nova Resource:
class QuestionDiagram extends Resource
{
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Image::make('Diagram', 'path'),
MorphTo::make('diagramable')->types([
Preamble::class,
Question::class,
])
];
}
}
Check if the types you are using are Nova resources and not models.
Please or to participate in this conversation.