Home > Net >  Route with ID from div
Route with ID from div

Time:04-10

How do you correctly route in Laravel when on click and pass the ID along? I have a using vue that prints out every element of an array. Like this:

<div v-for="album in albums" :key="album.id" >
    <a href="/album/">{{ album.title  }}</a>
  </div>

As you can see im trying to route using href. How can i pass the album.id alongside that? So the route would be for an example localhost:8000/album/5

Thanks for any help, i do appreciate it.

CodePudding user response:

@Gev99

Thanks for the reply mate.

I fixed it by doing this:

<div v-for="album in albums" :key="album.id" >
    <a v-bind:href="'/album/'  album.id"> {{ album.title }} </a>
  </div>

I will try out yours aswell! Thank you!

CodePudding user response:

//web.php
Route::get('albume/{id}',[MyController::class,'MyMethod'])->name('albume');

//in vue file

 <div v-for="(album,idx) in albums" :key="idx" >
    <a :href="route('album',album.id)">{{ album.title  }}</a>
  </div>

This is the best way

  • Related