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); }
grafixinfluenz liked this reply
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community