Support the ongoing development of Laravel.io →
10 months ago
Last updated 3 months ago.
0

In your migration, change your foriegn key line with this :

$table->foreign('category_id')->references('id')->on('categories');

In your Category model : (if you are calling the other model Object, so put objects in the function otherwise put the name of your model instead in plural)

public function objects(){ return $this->hasMany(Object::class); }

In your Object model :

public function category(){ return $this->belongsTo(Category::class); }

Last updated 10 months ago.
1

Thanks for your help !

1

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.