Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Auto hyperlinks inside article using given tags - Laravel

I am developing an article website, I have a list of 5-10 tags attached with each article.

Thing I am trying to achieve is if there is same exact word (from given tags) is used in article, it should hyperlinks to that tag/category.

For example tags are as following:

trading, financial, growth, imports, government

And article is like:

Government has put sanctions on imports from northern allies to stabilize its economy. This will support growth of GDP.

So according to my requirements government, imports & growth should be hyperlinked with abc.com/tags/imports.

How can I achieve this using laravel blade. Is their any package for that? I couldn't find any.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It makes sense to put the links to the article before you pass it to blade. After you've pulled the data from database you can handle it with some method based on str_replace (or str_ireplace for case-insensitive) like this:

public function addTagLinks(string $text, array $tags): string
{
  $links = [];
  foreach($tags as $tag) {
    $links[] = '<a href=' .url(...) . '>'.$tag.'</a>';
  }
  return str_replace($tags, $links, $text);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda