I'm using Laravel 8 with InertiaJS Vue2. I'm trying to pass data with hasMany relationship to the vue for editing. How do I put the relationship in Edit.vue for form editing and posting?
// Controller
class BooksController extends Controller
{
public function show(Request $request)
{
$book = Books::where('id',$request->id)->with('locations')->firstOrFail();
return Inertia::render('Admin/Books/Edit', ['book' => $book]);
}
}
// books model
class Books extends Model
{
public function locations()
{
return $this->hasMany(BookLocation::class);
}
}
// Edit.vue
<template>
...
<div v-for="location in book.locations">
<div>
<jet-label for="location" value="Location" />
<jet-input name="location" type="text" class="mt-1 block w-full" v-model="???"/>
</div>
</div>
</template>
...
<script>
data() {
return {
form: this.$inertia.form({
locations: this.book.locations???
})
}
},
</script>