Link | menu | Spatie

 SPATIE

  HTML Menu Generator
======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Menu](https://spatie.be/docs/menu/v1)  Api  Link

 Version   v3   v2   v1

 Other versions for crawler [v3](https://spatie.be/docs/menu/v3) [v2](https://spatie.be/docs/menu/v2) [v1](https://spatie.be/docs/menu/v1)

- [ Introduction ](https://spatie.be/docs/menu/v1/introduction)
- [ Postcardware ](https://spatie.be/docs/menu/v1/postcardware)
- [ Requirements ](https://spatie.be/docs/menu/v1/requirements)
- [ Installation and Setup ](https://spatie.be/docs/menu/v1/installation-and-setup)
- [ Questions &amp; Issues ](https://spatie.be/docs/menu/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/menu/v1/changelog)
- [ About Us ](https://spatie.be/docs/menu/v1/about-us)

Basic usage
-----------

- [ Your First Menu ](https://spatie.be/docs/menu/v1/basic-usage/your-first-menu)
- [ Adding Items ](https://spatie.be/docs/menu/v1/basic-usage/adding-items)

Items in depth
--------------

- [ Active Items ](https://spatie.be/docs/menu/v1/items-in-depth/active-items)
- [ Manipulating Items ](https://spatie.be/docs/menu/v1/items-in-depth/manipulating-items)
- [ Conditionally Adding Items ](https://spatie.be/docs/menu/v1/items-in-depth/conditionally-adding-items)

Controlling the html output
---------------------------

- [ Item Attributes ](https://spatie.be/docs/menu/v1/controlling-the-html-output/item-attributes)
- [ Parent Attributes ](https://spatie.be/docs/menu/v1/controlling-the-html-output/parent-attributes)
- [ Appending and Prepending Html ](https://spatie.be/docs/menu/v1/controlling-the-html-output/appending-and-prepending-html)

Menus in your Laravel app
-------------------------

- [ Convenience Methods ](https://spatie.be/docs/menu/v1/menus-in-your-laravel-app/convenience-methods)
- [ Conditional Items Based on Permissions ](https://spatie.be/docs/menu/v1/menus-in-your-laravel-app/conditional-items-based-on-permissions)
- [ Using Macros ](https://spatie.be/docs/menu/v1/menus-in-your-laravel-app/using-macros)

Examples
--------

- [ Bootstrap Menu ](https://spatie.be/docs/menu/v1/examples/bootstrap-menu)

API
---

- [ Menu ](https://spatie.be/docs/menu/v1/api/menu)
- [ Link ](https://spatie.be/docs/menu/v1/api/link)
- [ Html ](https://spatie.be/docs/menu/v1/api/html)

      You are viewing the documentation for **an older version** of this package. You can check the version you are using with the following command:

 `                                    composer show spatie/menu                                                                                                                                                                                                                                    `

Link
====

`Spatie\Menu\Link`
------------------------------------------------------------------------------------------------------

- Implements `Spatie\Menu\Activatable`, `Spatie\Menu\HasUrl`, `Spatie\Menu\HasHtmlAttributes`, `Spatie\Menu\HasParentAttributes`, `Spatie\Menu\Item`

### `to`

```
/**
 * @param string $url
 * @param string $text
 *
 * @return static
 */
public static function to(string $url, string $text)
```

### `getText`

```
/**
 * @return string
 */
public function getText() : string
```

### `getUrl`

```
/**
 * @return string
 */
public function getUrl() : string
```

### `segment`

```
/**
 * Return a segment of the link's URL. This function works for both absolute
 * and relative URL's. The index is a 1-index based number. Trailing and
 * double slashes are ignored.
 *
 * Example: (new Link('Open Source', 'https://spatie.be/opensource'))->segment(1)
 *      => 'opensource'
 *
 * @param int $index
 *
 * @return string|null
 */
public function segment(int $index)
```

### `prefix`

```
/**
 * @param string $prefix
 *
 * @return $this
 */
public function prefix(string $prefix)
```

### `render`

```
/**
 * @return string
 */
public function render() : string
```

### `isActive`

```
/**
 * @return bool
 */
public function isActive() : bool
```

### `setActive`

```
/**
 * @return $this
 */
public function setActive()
```

### `setInactive`

```
/**
 * @return $this
 */
public function setInactive()
```

### `setAttribute`

```
/**
 * @param string $attribute
 * @param string $value
 *
 * @return $this
 */
public function setAttribute(string $attribute, string $value = '')
```

### `addClass`

```
/**
 * @param string $class
 *
 * @return $this
 */
public function addClass(string $class)
```

### `getParentAttributes`

```
/**
 * Return an array of attributes to apply on the parent. This generally means
 * the attributes that should be applied on the  tag.
 *
 * @return array
 */
public function getParentAttributes() : array
```

### `setParentAttribute`

```
/**
 * @param string $attribute
 * @param string $value
 *
 * @return $this
 */
public function setParentAttribute(string $attribute, string $value = '')
```

### `addParentClass`

```
/**
 * @param string $class
 *
 * @return $this
 */
public function addParentClass(string $class)
```

`Spatie\Menu\Laravel\Link`
----------------------------------------------------------------------------------------------------------------------------

- Extends `Spatie\Menu\Link`
- Uses `Illuminate\Support\Traits\Macroable`

```
/**
 * @param string $path
 * @param string $text
 * @param array $parameters
 * @param bool|null $secure
 *
 * @return $this
 */
public static function url(string $path, string $text, array $parameters = [], $secure = null)
```

```
/**
 * @param string $action
 * @param string $text
 * @param array $parameters
 * @param bool $absolute
 *
 * @return $this
 */
public static function action(string $action, string $text, array $parameters = [], bool $absolute = true)
```

```
/**
 * @param string $name
 * @param string $text
 * @param array $parameters
 * @param bool $absolute
 * @param \Illuminate\Routing\Route|null $route
 *
 * @return $this
 */
public static function route(string $name, string $text, array $parameters = [], $absolute = true, $route = null)
```
