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

182
Visualizações
Display html blade delete button from javascript

I've a tchat with websocket and I wan't to delete message by clicking on button.

Each message are displayed with this function :

const displayMessage = (message, author, icon, color, time) => {
            let url = '{!! route('users.profile', ":name") !!}'.replace(':name', author);
            let currentUser = '{!! Auth::user()->username !!}'
            let whoClass = currentUser === author ? "me" : "other"
            return `
                <div class="message ${whoClass}" data-username="${author}">
                    <p>${message}</p>
                    <span class="sub_message">
                        <i class="fad ${icon} text-${color}"></i>
                        <a href="` + url + `">${author}</a>
                            - ${time}
                       ${deleteBtn(author)}
                    </span>
                </div>
                `
        }

But I use a policy with @can to display the button only for admin user and other condition : moderator can't delete message of admin, but this is not the problem.

How can I display this @can directive on JS ? with ${author} variable

const deleteBtn = (author) => {
            @can('deleteTchatMessage', ${author})
                <form class="d-inline" action="{{ route('index') }}" method="POST">
                    @method('DELETE')
                    @csrf
                    <button class="btn" type="submit" onclick="return confirm('Are you sure you want to delete it ?')">
                    <i class="fad fa-trash text-red"></i>
                    </button>
                </form>
            @endcan
        }

At the moment, it doesn't recognize the author variable, so I must be doing it wrong

about 4 years ago · Juan Pablo Isaza
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