$categories = Category::find(1); $array = $categories->contents->toArray(); echo "<pre>"; print_r($array); echo $array[0]['pivot']['category_id']; die; 

How to get contents from collections of $ categories without an array?

Category.php model

  public function contents() { return $this->belongsToMany('App\Content'); } 
  • namely need pivot-> content_id - Yerzhan
  • What for ? you also have an array of contents now the contents and take an id there, since you wrote you can get access to "extra fields", for example if you had an active table in the table - Orange_shadow

0