I have a global variable that I need to pass to my query:
$size = (user input)
$name = (user input)
$items = Items::with('color')->with(['size' => function ($query){
$query->where('meters', '=', $size);
}])
->where('item_name', '=', $name)
->get();
The problem with this query is that the $color variable is not available in the closure: I really need to eager load the data instead of joining tables as I already defined a variable that is used in the view. How can I pass that variable to the closure?