hi i have many to many polymorphic Relation
When I use the sync method to insert data in the interface table, I encounter this error. What is the problem?
controller code:
$job_create->skills()->sync($request['skill']);
job model:
public function skills(){
$this->morphMany(Skil::class,'skillables');
}
skill model:
public function jobs()
{
return $this->morphedByMany(Job::class, 'skillables');
}
2
Answers
Relationships should always return the relation.
first make sure that given Skil::class is correct i think it must be Skill::class
the error says that $job_create->skills() is null you can test it with dd();
if the problem didn’t solved just study the documentation:
https://laravel.com/docs/9.x/eloquent-relationships#many-to-many-polymorphic-relations