public static function indexBy(Array &$array, $key=null, $obj2Array=false)
    {
        // Use model instance's primary key while no given key
        $key = ($key) ?: (new static())->primaryKey;

        $tmp = [];
        foreach ($array as $row) {
            // Array & Object types support 
            if (is_object($row) && isset($row->$key)) {
                
                $tmp[$row->$key] = ($obj2Array) ? (array)$row : $row;
            } 
            elseif (is_array($row) && isset($row[$key])) {
                
                $tmp[$row[$key]] = $row;
            }
        }
        return $array = $tmp;
    }