Illuminate\Routing\UrlGenerator::to PHP Method

to() public method

Generate an absolute URL to the given path.
public to ( string $path, mixed $extra = [], boolean | null $secure = null ) : string
$path string
$extra mixed
$secure boolean | null
return string
    public function to($path, $extra = [], $secure = null)
    {
        // First we will check if the URL is already a valid URL. If it is we will not
        // try to generate a new one but will simply return the URL as is, which is
        // convenient since developers do not always have to check if it's valid.
        if ($this->isValidUrl($path)) {
            return $path;
        }
        $scheme = $this->getScheme($secure);
        $extra = $this->formatParameters($extra);
        $tail = implode('/', array_map('rawurlencode', (array) $extra));
        // Once we have the scheme we will compile the "tail" by collapsing the values
        // into a single string delimited by slashes. This just makes it convenient
        // for passing the array of parameters to this URL as a list of segments.
        $root = $this->getRootUrl($scheme);
        if (($queryPosition = strpos($path, '?')) !== false) {
            $query = substr($path, $queryPosition);
            $path = substr($path, 0, $queryPosition);
        } else {
            $query = '';
        }
        return $this->buildCompleteUrl($root, $path, $tail) . $query;
    }

Usage Example

Esempio n. 1
2
 public function withBrand($brand, $link = null)
 {
     if (!isset($link)) {
         $link = $this->url->to('/');
     }
     $this->brand = compact('brand', 'link');
     return $this;
 }
All Usage Examples Of Illuminate\Routing\UrlGenerator::to