title: How to create relationship between POPOs models?
body: <p>The biggest problem with applying repository pattern in Laravel is that the Eloquent Model has many powers and letting those powers reach the application layer will leave us with no control over the domain service layer.</p>
  
  <p>The solution I found for this was to create new models with less power, resembling POPOs (plain old php objects). So far, everything is going well. I make queries that return Eloquent Models and, when I need to pass the data to the application service layer, a Middle Man acts as a parser that turns Eloquent Models into POPOs models.</p>
  
  <p>Now the problem I'm actually facing is a conflict of concept. Let's look at the example.</p>
  
  <p>I have the following structures:</p>
  
  <p>Plan:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>amount</li>
  </ul>
  
  <p>Coupon:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>code</li>
  <li>plan_id</li>
  </ul>
  
  <p>Based on this structure, when making the following query:</p>
  
  <pre><code>Coupon::select(['plans.name as plan_name', 'plans.amount as plan_amount', 'coupons.*'])-&gt;leftJoin('plans', 'plans.id', '=', 'coupons.plan_id')-&gt;get();
  </code></pre>
  
  <p>Coupon and plan values ​​will be returned in the same query.</p>
  
  <p>Now things just get interesting. As mentioned above, I am using a new model, different from the Eloquent Model, and in certain situations I need these models to relate.</p>
  
  <p>My question is: how to make this relationship between these models, so that at certain times the POPO Model Coupon has Plans information, according to queries made in the database? I need to somehow identify that the coupon query has plan information to create the relationship between the objects (via composition, aggregation, or any other way).</p>