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.
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,
]);
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,
]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With