add a : before your property pass in blade
<FollowButton :user-id="{{ $user->id }}"></FollowButton>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Can't get this code to work properly. Trying to get this vue button to work. Im using Laravel 9, Vite and Vue 3
error:
xhr.js:247 POST http://jotking.test/follow/undefined 404 (Not Found)
dispatchXhrRequest @ xhr.js:247
xhr @ xhr.js:49
dispatchRequest @ dispatchRequest.js:51
request @ Axios.js:142
httpMethod @ Axios.js:181
wrap @ bind.js:5
followUser @ FollowButton.vue:20
_createElementVNode.onClick._cache.<computed>._cache.<computed> @ FollowButton.vue:3
callWithErrorHandling @ runtime-core.esm-bundler.js:173
callWithAsyncErrorHandling @ runtime-core.esm-bundler.js:182
invoker @ runtime-dom.esm-bundler.js:345
settle.js:19 Uncaught (in promise) AxiosError {message: 'Request failed with status code 404', name: 'AxiosError', code: 'ERR_BAD_REQUEST', config: {…}, request: XMLHttpRequest, …}
FollowButton.vue
<template>
<div>
<button class="btn" @click="followUser">Follow</button>
</div>
</template>
<script>
import axios from "axios";
export default {
mounted() {
console.log("Component mounted.");
},
props: ["userId"],
methods: {
followUser() {
// axios.post("/follow/1") <-- this registers
axios.post("/follow/" + this.userId) <-- this gives me error
.then((response) => {
console.log(response.data);
});
},
},
};
</script>
index.blade.php
<FollowButton user-id="{{ $user->id }}"></FollowButton>
</div>
FollowsController.php
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
class FollowsController extends Controller
{
public function store(User $user)
{
return auth()->user()->following()->toggle($user->profile);
// return $user->username;
}
}
Please or to participate in this conversation.