Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Shiva's avatar

How to get a title attribute in HTML::link

I have a link that looks like this

<a href="{{ $port->id }}" title="{{ $port->title }}" target="_blank"><img src={{ "pcategory_images/$portImg" }}></a>

and I would like to use the HTML::link code. The problem I'm having is that I'm not sure how to get the title="{{ $port->title }}" with the HTML::link

0 likes
2 replies
mstnorris's avatar

@Shiva why do you want to use the HTML facade? Stick to normal HTML, the facades don't save you any time. They are less readable.

RomainLanz's avatar

Just check the function.

/**
 * Generate a HTML link.
 *
 * @param string $url
 * @param string $title
 * @param array  $attributes
 * @param bool   $secure
 *
 * @return string
 */
public function link($url, $title = null, $attributes = [], $secure = null)
{
    $url = $this->url->to($url, [], $secure);
    if (is_null($title) || $title === false) {
        $title = $url;
    }
    return '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
}

Please or to participate in this conversation.