[9.x] Add whereNotMorphedTo, orWhereNotMorphedTo

Merged
PA
4y ago
+102-0

This PR adds the inverse of whereMorphedTo, and orWhereMorphedTo.

I've also added tests for new methods and missing test for orWhereMorphedTo.

The following code could be extracted to a static method on Relation as it's now duplicated.

$morphMap = Relation::morphMap();

if (! empty($morphMap) && in_array($model, $morphMap)) {
    $model = array_search($model, $morphMap, true);
}

I wasn't sure on the terminology from the morph map, are they called "keys", or "morph type values", something else? :D

Then I noticed there was already a getMorphedModel static method

public static function getMorphedModel($alias)
{
    return static::$morphMap[$alias] ?? null;
}

Anyway I'm open to suggestion on the naming if this code should be extracted.