public static function fromString($rawRelation)
    {
        //name:assets;type:hasMany;params:App\\Models\\Asset|category_id|id,
        // expected string
        //name|type|params|field
        //assets|hasMany|App\\Models\\Asset,category_id,id|title

        $parts = explode(';', $rawRelation);
        $collection = [];
        foreach ($parts as $part) {
            if (!str_contains($part, ':')) {
                continue;
            }

            list($key, $value) = explode(':', $part);

            if ($key == 'params' || str_contains($value, '|')) {
                $value = explode('|', $value);
            }

            $collection[$key] = $value;
        }

        return self::get($collection);
    }
public static function fromString($rawRelation)
    {
        //name:assets;type:hasMany;params:App\\Models\\Asset|category_id|id,
        // expected string
        //name|type|params|field
        //assets|hasMany|App\\Models\\Asset,category_id,id|title

        $parts = explode(';', $rawRelation);
        $collection = [];
        foreach ($parts as $part) {
            if (!str_contains($part, ':')) {
                continue;
            }

            list($key, $value) = explode(':', $part);

            if ($key == 'params' || str_contains($value, '|')) {
                $value = explode('|', $value);
            }

            $collection[$key] = $value;
        }

        return self::get($collection);
    }
public static function fromString ( $ rawRelation ) { //name:assets;type:hasMany;params:App\\Models\\Asset|category_id|id, // expected string //name|type|params|field //assets|hasMany|App\\Models\\Asset,category_id,id|title $ parts = explode ( ';' , $ rawRelation ) ; $ collection = [ ] ; foreach ( $ parts as $ part ) { if ( ! str_contains ( $ part , ':' ) ) { continue ; } list ( $ key , $ value ) = explode ( ':' , $ part ) ; if ( $ key == 'params' || str_contains ( $ value , '|' ) ) { $ value = explode ( '|' , $ value ) ; } $ collection [ $ key ] = $ value ; } return self :: get ( $ collection ) ; }
Get a foreign relationship from given string

@param string $rawRelation

@return null | ForeignRelationship
Get a foreign relationship from given string