Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method Illuminate\View\View::response does not exist

I'm getting an error when I want to fetch my data from table.

My controller :

public function admin()
{
    $users = User::with('subs')->get();
    return view('admin')->response()->json([
        'users' => $users,
    ], 200);
}

My vue.js script :

export default {
    data() {
        return {
            users: []
        }
    },

    methods: {
        showUsers() {
            axios.get('admin/routes').then(response => {
                this.users = response.data.users;
            });
        }
    },
    mounted() {
        this.showUsers();
    }
}

My blade html code:

<tr v-for="user in users">
    <td>{{ user.id }}</td>
    <td>{{ user.name }}</td>
</tr>

Method Illuminate\View\View::response does not exist.

When I want to fetch my data from table.

like image 677
iAmGroot Avatar asked Oct 15 '22 13:10

iAmGroot


2 Answers

Everything is fine in your code just send only response because we only want database table's data, no need to return view.

return response()->json([
    'users' => $users,
]);
like image 104
Aafiya Hanafi Avatar answered Nov 15 '22 10:11

Aafiya Hanafi


You don't need to return view for that since you just need the JSON response for the API to work.

return response()->json([
    'users' => $users,
]);
like image 36
Adlan Arif Zakaria Avatar answered Nov 15 '22 10:11

Adlan Arif Zakaria