当我想从表中获取数据时出现错误。
我的 Controller :
public function admin()
{
$users = User::with('subs')->get();
return view('admin')->response()->json([
'users' => $users,
], 200);
}
我的 vue.js 脚本:
export default {
data() {
return {
users: []
}
},
methods: {
showUsers() {
axios.get('admin/routes').then(response => {
this.users = response.data.users;
});
}
},
mounted() {
this.showUsers();
}
}
我的 blade html 代码:
<tr v-for="user in users">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
</tr>
Method Illuminate\View\View::response does not exist.
当我想从表中获取数据时。
最佳答案
您的代码中的一切都很好,只发送响应,因为我们只需要数据库表的数据,不需要返回 View 。
return response()->json([
'users' => $users,
]);
关于laravel - 方法 Illuminate\View\View::response 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56846218/