Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vampiremr's avatar

morphToMany relationship in current table

Hi I have table "projects" with field BasedOnId And I want to create morphToMany relationsship in current table

In resource Projects I create field

MorphToMany::make(\App\Nova\Projects::label(), 'based', '\App\Nova\Projects') ->searchable() ->singularLabel(\App\Nova\Projects::singularLabel())

And in model Projects I want to create "based" funtion, but how I can do it with same table?

Code

public function based()
{
   return $this->belongsToMany('App\Models\Projects', 'projects', 'basedOnId', 'id');
}

not work

How I can do it?

0 likes
0 replies

Please or to participate in this conversation.