Issue
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.
Solution
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,
]);
Answered By - Adlan Arif Zakaria
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.