title: Laravel - Model and Function
body: <p>I have some table like the follows:</p>
  
  <pre><code>id
  name
  parent_id
  ...
  </code></pre>
  
  <p>The parent_id is the id from the same table itself as it is something simple. For example:</p>
  
  <pre><code>id: 1
  name: abc
  parent_id: 0
  
  id: 2
  name: abc_parent
  parent_id: 1
  
  id: 3
  name: another
  parent_id: 1
  </code></pre>
  
  <p>How can I get the "name" inside some function in that model? Something like...</p>
  
  <pre><code>public function parentName()
  {
      $pid = this-&gt;parent_id;
      /// return self::find($pid)-&gt;name; ### this does not actually work
  }
  </code></pre>
  
  <p>Should I create a separate function and pass the parent_id to it? or is there any simpler way?</p>