Spatie\Menu\Helpers\Str::removeFromStart PHP Метод

removeFromStart() публичный статический Метод

public static removeFromStart ( string $remove, string $subject ) : string
$remove string
$subject string
Результат string
    public static function removeFromStart(string $remove, string $subject) : string
    {
        if (!self::startsWith($subject, $remove)) {
            return $subject;
        }
        return self::replaceFirst($remove, '', $subject);
    }

Usage Example

Пример #1
0
 /**
  * @param string $url
  * @param string $root
  *
  * @return $this
  */
 public function determineActiveForUrl(string $url, string $root = '/')
 {
     if (!$this->hasUrl()) {
         return;
     }
     $itemUrl = Url::fromString($this->url);
     $matchUrl = Url::fromString($url);
     // If the hosts don't match, this url isn't active.
     if ($itemUrl->getHost() !== $matchUrl->getHost()) {
         return $this->setInactive();
     }
     // If this url doesn't start with the root, it's inactive.
     if (!Str::startsWith($itemUrl->getPath(), $root)) {
         return $this->setInactive();
     }
     // For the next comparisons we just need the paths, and we'll remove
     // the root first.
     $itemPath = Str::removeFromStart($root, $itemUrl->getPath());
     $matchPath = Str::removeFromStart($root, $matchUrl->getPath());
     // If this url starts with the url we're matching with, it's active.
     if (Str::startsWith($matchPath, $itemPath)) {
         return $this->setActive();
     }
     return $this->setInactive();
 }