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

El conde Lucanor's avatar

My vue template don't work very well with Laravel hrefs, why?

I'm trying to do a simple href in my vue template, but for some reason my Laravel Mix can't compilate the code.

In a Laravel .blade I'm using <a href="{{ route('inscripcionesweb.edit', $inscripcionesweb->INS_WEB_ID) }}"> as example that what I want.

In this Vue the :href ="{{ route('inscripcioneswebs.edit', $inscripcionesweb->INS_WEB_ID) }} is the main error, the rest of code works perfectly.

template.vue

<template>
    <table id="myTable">
        <thead>
            <tr>
                <th>ID</th>
                <th>NAME</th>
            </tr>
        </thead>
        <tbody>
            <tr v-for="inscripcionesweb in inscripcioneswebs" >
                <td> 
                    <a :href ="{{ route('inscripcioneswebs.edit', $inscripcionesweb->INS_WEB_ID) }}"> 
                        {{ inscripcionesweb.INS_WEB_ID }} 
                    </a>
                </td>
                <td> {{ inscripcionesweb.INS_WEB_CUR_NAME }} </td>
            </tr>
        </tbody>
    </table>
</template>

<script>
    import datatables from 'datatables'

    export default {
        mounted() {
            this.getInscripcionesWebs()
        },

        data() {
            return {
                inscripcioneswebs: [],
            }
        },

        methods: {
            myTable() {
                $(function () {
                    $('#myTable').DataTable();
                });
            },

            getInscripcionesWebs() {
                var urlInscripcionesWebs = "inscripcioneswebs/show";
                axios.get(urlInscripcionesWebs).then(response => {
                    this.inscripcioneswebs = response.data
                    this.myTable()
                })
            },
        }
    }
</script>

I tried too with:

<a :href="route('inscripcioneswebs.edit', $inscripcionesweb->INS_WEB_ID)">  
    {{ inscripcionesweb.INS_WEB_ID }} 
</a>
<a :href="inscripcioneswebs/{{ inscripcionesweb.INS_WEB_ID }}/edit">  
    {{ inscripcionesweb.INS_WEB_ID }} 
</a>
<a :href="inscripcioneswebs/inscripcionesweb.INS_WEB_ID/edit">  
    {{ inscripcionesweb.INS_WEB_ID }} 
</a>

But nothing...

I must use some part of <script> section to work?

0 likes
9 replies
vincent15000's avatar

You have an error in your route method. The second parameter has to be an array.

route('inscripcioneswebs.edit', ['INS_WEB_ID' => $inscripcionesweb->INS_WEB_ID])
vincent15000's avatar

@El conde Lucanor

The {{ ... }} are necessary ;).

{{ route('inscripcioneswebs.edit', ['INS_WEB_ID' => $inscripcionesweb->INS_WEB_ID]) }}

And this allows you to use the $INS_WEB_ID variable in your blade template.

Please or to participate in this conversation.