laravel - 方法 Illuminate\View\View::response 不存在

标签 laravel vue.js laravel-5 vuejs2

当我想从表中获取数据时出现错误。

我的 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/

相关文章:

vue.js - 如何使用 Vuetify 反转标题方向?

php - 在套件中的每个测试之前运行设置代码

javascript - Vue.js 破坏了 Google map 功能

php - Mac M1 无法将 PHP 8.0 映射为 PhpStorm 中的 CLI 解释器

javascript - Vuejs - 添加显示 block 时 tr 行未显示 100%

javascript - 在 vuex 操作中使用 fetch 方法

php - 在angularJs中访问对象时出现未定义错误

email - 如何在 laravel 5 中使用队列通过电子邮件发送密码重置链接

php - Laravel 403 禁止错误

mysql - 使用 Laravel 检索和编辑页面上的数据