title: Laravel get value from my function in Model
body: <p>My model Dispatch has a field invoice_id.
  It is a foreign key so i can get the invoice details using the below code:</p>
  
  <pre><code>protected $fillable = [
      'id',
      'truck_no',      
      'driver_name',      
      'driver_phone',      
      'gps_details',      
      'invoice_id',      
  ];
  
  public function invoice(){
      return $this-&gt;belongsTo('App\Invoice')-&gt;select('id','invoice_no','permit_id');
  }
  </code></pre>
  
  <p>Now I want to get the value permit_id from invoice() so i can use it to get the details of the Permit.</p>
  
  <p><strong>permit_id = id of Permit model</strong></p>
  
  <p>So I use the below code to get the permit data.</p>
  
  <pre><code>public function permit(){
      return $this-&gt;hasOne('App\Permit','id',$this-&gt;invoice()-&gt;permit_id);
  }
  </code></pre>
  
  <p>Update:</p>
  
  <p>My Invoice Model has :</p>
  
  <pre><code>class Invoice extends Model
  {
      protected $fillable = [
          'id',
          'invoice_no',
          'invoice_date',
          'permit_id',
      ];
  
      public function permit(){
          return $this-&gt;hasOne('App\Permit', 'id', 'permit_id');
      }
  }
  </code></pre>
  
  <p>My Permit Model has:</p>
  
  <pre><code>class Permit extends Model
  {
      protected $fillable = [
          'permit_type',
          'permit_no',
          'application_no',  
          'supply_unit', 
          'supply_unit_id' ,  
       ];
  
      public function supplyunit(){
          return $this-&gt;hasOne('App\SupplyUnit','id','supply_unit_id');
      }
  }
  </code></pre>
  
  <p>And as per suggestions i have added below code in my Dispatch Model:</p>
  
  <pre><code> class Dispatch extends Model
    {
      protected $fillable = [
          'id',
          'truck_no',      
          'driver_name',      
          'driver_phone',      
          'gps_details',      
          'invoice_id',      
      ];
  
      public function invoice(){
          return $this-&gt;hasOne('App\Invoice','id','invoice_id');
      }
  
      public function permit(){
          return $this-&gt;hasOne('App\Permit','id','permit_id');
      }
    }
  </code></pre>
  
  <p>But it doesn't work. What should i do to achieve the above? Is there any other solutions please suggest.</p>