title: Eager Loading Validation in Laravel
body: <p>I am having some trouble figuring out how to validate that an entire eager loaded query is valid before going on with my order of operations.</p>
  
  <pre><code>public function subIndex($box, $variant) {
  
    $boxes = Boxes::where('planId', '=', 1)
             -&gt;where('handle', '=', $box)
             -&gt;with(array('variants' =&gt; function($query) use ($variant) {
               $query-&gt;where('handle', '=', $variant)-&gt;with('products');
              }))-&gt;first();
  
    if($boxes) {
  
      return View::make('checkout.select', array('boxes' =&gt; $boxes));
  
    }
  
    return Redirect::to('/');
  
  }
  </code></pre>
  
  <p>It seems that the closure's result is irrelevant to the if check. Thus resulting in "Undefined offset:" errors in my view.</p>
  
  <p>If the "box" is invalid, the error occurs, but if the closure's query is invalid, it will still fire off. I know there are 2 queries being created here, but am unsure on how to check if the second query was valid.</p>
  
  <p>Am I being too greedy with trying to minimize my queries when it comes to validation?</p>