I am finding that I often need to select a field, based on a condition other than the id.
So, $user = User::where('last_login', $lastLogin)->where('last_warning', $lastWarning)->get(); works perfectly.
That is until you set one of the where's to allow nulls (let's do last_login).
That is, it can either have a value or be null.
That means you need to use one of two function where() or whereNull() and to do that you need to break the chain, so it becomes
$user = User::where('last_warning', $lastWarning);
is_null($lastLogin) ? $user->whereNull('last_login') : $user->where('last_login', $lastLogin);
$user = $user->get();
I am wondering if where has a way to deal with this? as currently if you pass null through to where you get where column = null which doesn't work!