title: Laravel Eloquent get data from multiple related table
body: <p>i have a deliveryForecast model and i have to create an eloquent to get data from multiple table based on 2 columns.</p>
  
  <p>this is my delivery_forecasts table</p>
  
  <pre><code>Schema::create('delivery_forecasts', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;enum('type',array('Quotation','Demo','Service Unit','Freebie','Back Job','Site Visit'));
          $table-&gt;string('type_id');
          $table-&gt;date('transaction_date');
          $table-&gt;time('transaction_time')-&gt;nullable();
          $table-&gt;enum('status',array('Pending','Approved','Cancelled'))-&gt;default('Pending');
          $table-&gt;boolean('queue')-&gt;default(0);
          $table-&gt;timestamps();
      });
  </code></pre>
  
  <p>the question is can i create the eloquent in model? or how to make condition?  </p>
  
  <p>for example:</p>
  
  <pre><code>class DeliveryForecast extends Model
  {
      public function documents(){
          if(DeliveryForecast-&gt;type == 'Quotation'){
              return $this-&gt;belongsTo('App\Quotation','type_id','id');
          }
          if(DeliveryForecast-&gt;type == 'Demo'){
              return $this-&gt;belongsTo('App\Demo','type_id','id');
          }
          if(DeliveryForecast-&gt;type == 'Service Unit'){
              return $this-&gt;belongsTo('App\ServiceUnit','type_id','id');
          }
          and so on .....
      }
  }
  </code></pre>
  
  <p>i don't have idea to create the condition to eloquent and my query should be like this:  </p>
  
  <pre><code>$delivery_forecast = DeliveryForecast::with('documents')
          -&gt;get();
  </code></pre>
  
  <p>any idea guys? thanks in advance.</p>