【发布时间】:2021-05-30 17:05:06
【问题描述】:
我正在使用 Laravel 8 和 InertiaJS Vue2。我正在尝试将具有 hasMany 关系的数据传递给 vue 进行编辑。如何将关系放入 Edit.vue 以进行表单编辑和发布?
// 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>
【问题讨论】:
标签: vuejs2 laravel-8 inertiajs