Attempting to emulate a LEFT JOIN
using Eloquent and receiving an error. Basically, I am trying to get Users
with addresses
, but only of a certain type.
This code does not work, but I think you will get the gist:
$user = User::with('addresses', 'cards')->where(function($query) {
$query->where('address.type', '=', 'shipping');
})->find(Auth::user()->id);
If I leave off the where
it works fine, but more addresses returned than I need/want.
How can I make it so I only get addresses with a type = 'shipping'? I might want to do the same thing with cards
as well. If there are no shipping addresses, I still want everything else.
I was trying to use Eloquent vs Fluent/DB (which I did make work), but just can't figure it out.
Follow-up: Depending on what version of PHP you have, you may need to do array(load array)
vs. [load array]
. Dev and Prod are not always the same.