Skip to content

Instantly share code, notes, and snippets.

@MarGul
Last active April 13, 2018 09:36
Show Gist options
  • Save MarGul/46413331b341176cca01fb05c52163f6 to your computer and use it in GitHub Desktop.
Save MarGul/46413331b341176cca01fb05c52163f6 to your computer and use it in GitHub Desktop.
// Document model
public function connectedWith()
{
return $this->belongsToMany('App\Models\Document', 'connection_document', 'document_id', 'connected_id');
}
public function connectedTo()
{
return $this->belongsToMany('App\Models\Document', 'connection_document', 'connected_id', 'document_id');
}
/**
* When this model is converted to an array (JSON response)
*
* @return array
*/
public function toArray() {
// When I remove the comments from connectedTo and connectedWith it goes crazy
return [
'id' => $this->id,
'pages' => $this->pages,
//'connectedWith' => $this->connectedWith,
//'connectedTo' => $this->connectedTo
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment