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

arturk's avatar

Eloquent Many To Many Relation Does not return data

I'm trying to make my application with belongsToMany function and pivot Table. I have 3 tables

---forums | ---categories | ---categorie_forum

Forum model: public function categories() { return $this->belongsToMany('App\Entities\Categorie','categorie_forum','forum_id','categorie_id'); }

Categotie model:

public function forum() { return $this->belongsToMany('App\Entities\Forum','categorie_forum','categorie_id','forum_id'); }

In my controller I'm calling following script: public function test(){ $categories = Forum::find(1)->categories(); return response()->json($categories); }

Response return empty json.

What am I doing wrong?

0 likes
0 replies

Please or to participate in this conversation.