Support the ongoing development of Laravel.io →
posted 2 years ago
Last updated 1 year 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 2 years ago.

grafixinfluenz liked this reply

1

Thanks for your help !

abdouweb liked this reply

1

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.