title: Get object only when relation result is exist [laravel]
body: <p>I have a problem with get data only when relation query count is more than 0.</p>
  
  <p>This is my model of <strong>customer</strong> with relation</p>
  
  <pre><code>class Customer extends Model
  {
      protected $table = 'customers';
  
      public function contracts()
      {
          return $this-&gt;hasMany('App\Contract');
      }
  </code></pre>
  
  <p>This is my model of <strong>contracts</strong></p>
  
  <pre><code>class Contract extends Model
  {
      public function customer()
      {
          return $this-&gt;belongsTo('App\Customer');
      }
  }
  </code></pre>
  
  <p>On the end i need only customers who they contracts beetwen some date</p>
  
  <pre><code>$customers = Customer::with(['contracts' =&gt; function($query)
       {
          $query-&gt;where('data_end','&gt;=','2017-07-01')
                -&gt;where('data_end','&lt;=','2017-07-31') 
                -&gt;where('typ','=','U') ;
       }
      ])-&gt;paginate(10);
  </code></pre>
  
  <p>But i have all customers. and it looks like this:</p>
  
  <pre><code>"Customer 1"
  "Customer 2"
  "Customer 3"
    *"Contract 1"
    *"Contract 2"
    *"Contract 3"
  "Customer 4"
    *"Contract 1"
    *"Contract 2"
    *"Contract 3"  
  "Customer 4"  
  </code></pre>
  
  <p>In this example i don't need customer 1,2, and 5. How can i do it with eager loading and object with relation on the end.</p>
  
  <p><a href="https://i.stack.imgur.com/9xwau.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>This is happen, i dont need customer with X on the screenshot - I mean, I don't need customer with 0 contracts from where query</p>
  
  <p>-- Object from dd()--</p>
  
  <p>end of this query
  2 customer, 1st have 2 contracts, 2nd have 0 contracts</p>
  
  <pre><code>LengthAwarePaginator {#217 ▼
    #total: 75000
    #lastPage: 37500
    #items: Collection {#213 ▼
      #items: array:2 [▼
        0 =&gt; Customer {#220 ▼
          #table: "customers"
          #connection: null
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:5 [▼
            "id" =&gt; 1
            "customer_number" =&gt; "46071600600"
            "name" =&gt; "Nikodem Zalewski"
            "customer_contact" =&gt; "507614445"
            "customer_type" =&gt; "P"
          ]
          #original: array:5 [▶]
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #events: []
          #observables: []
          #relations: array:1 [▼
            "contracts" =&gt; Collection {#224 ▼
              #items: array:2 [▼
                0 =&gt; Contract {#227 ▼
                  #connection: null
                  #table: null
                  #primaryKey: "id"
                  #keyType: "int"
                  +incrementing: true
                  #with: []
                  #perPage: 15
                  +exists: true
                  +wasRecentlyCreated: false
                  #attributes: array:10 [▶]
                  #original: array:10 [▶]
                  #casts: []
                  #dates: []
                  #dateFormat: null
                  #appends: []
                  #events: []
                  #observables: []
                  #relations: []
                  #touches: []
                  +timestamps: true
                  #hidden: []
                  #visible: []
                  #fillable: []
                  #guarded: array:1 [▶]
                }
                1 =&gt; Contract {#229 ▶}
              ]
            }
          ]
          #touches: []
          +timestamps: true
          #hidden: []
          #visible: []
          #fillable: []
          #guarded: array:1 [▶]
        }
        1 =&gt; Customer {#221 ▼
          #table: "customers"
          #connection: null
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:5 [▶]
          #original: array:5 [▼
            "id" =&gt; 2
            "customer_number" =&gt; "81050371854"
            "name" =&gt; "Adam Wróbel"
            "customer_contact" =&gt; "560047958"
            "customer_type" =&gt; "P"
          ]
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #events: []
          #observables: []
          #relations: array:1 [▼
            "contracts" =&gt; Collection {#222 ▼
              #items: []
            }
          ]
          #touches: []
          +timestamps: true
          #hidden: []
          #visible: []
          #fillable: []
          #guarded: array:1 [▶]
        }
      ]
    }
    #perPage: 2
    #currentPage: 1
    #path: "*"
    #query: []
    #fragment: null
    #pageName: "page"
  }
  </code></pre>