'Laravel inertia link with id
Hello I am beginner in using inertia and laravel, I want to pass an id from the web.php
routes of my laravel and i receive error.
Here is my web.php:
Route::get('/member/{member}/show', [MemberController::class, 'show'])->name('member.show');
now my route/href is like this:
<inertia-link class="btn btn-primary btn-sm" href="/member/{{ member.id }}/show">
can anyone help me fix the href="/member/{{ member.id }}/show"
Solution 1:[1]
you can use
<InertiaLink :href="route('member.show', { id: member.id })">
show
</InertiaLink>
for more info here
Solution 2:[2]
If you want to link to a new vue component
, send an id
and show the id
in the url
, you can do this:
Vue side
:
<template>
<button @click="submit">Open page with id in url</button>
</template>
<script setup>
import {Inertia} from "@inertiajs/inertia";
const submit = () => {
const id = 1
Inertia.post('/yourUrl/' + id, {id: id}) //{id: id} key-value-pair of id
}
</script>
Laravel side (web.php)
:
Route::post('/yourUrl/{id}', function (Request $request) {
return inertia('yourVueComponent', ['id' => $request->id]);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mohamed elshazly |
Solution 2 | Artur Müller Romanov |