I'm just getting into laravel and don't have any knowledge of vuejs either i have a very simple code that is trying to send to the server a request and the server should return an alert with username on it here is my code.
blade.php
<button user-id="{{ $user->id }}"></button>
vue compenent
<template>
<div>
<a href="#" class="btn btn-primary" onclick="action">Follow</a>
</div>
</template>
<script>
export default{
props: [userId],
mounted(){
console.log('Component mounted.')
},
methods:{
action(){
axious.post('/follow/' + this.userId)
.then( response => {
alter( response.data )
})
}
}
}
</script>
php code
route
Route::post('/follow/{user}', [ProfileController::class, 'store'];
Profile controller class
public function store(User $user){
return $user->username;
}
error
app.js:285 POST http://localhost:8000/follow/2 500 (Internal Server Error)
dispatchXhrRequest @ app.js:285
xhrAdapter @ app.js:119
dispatchRequest @ app.js:765
Promise.then (async)
request @ app.js:542
Axios.<computed> @ app.js:567
wrap @ app.js:1131
followUser @ app.js:1924
invokeWithErrorHandling @ app.js:39512
invoker @ app.js:39837
original._wrapper @ app.js:45196
app.js:699 Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:699)
at settle (app.js:960)
at XMLHttpRequest.handleLoad (app.js:168)
I just found the error i was not importing the class User in the ProfileController class.
Thank you all for your quick response.
下次当您处理 api 请求并出现这样的错误时,只需切换到网络点击开发人员工具并跟踪您的请求,然后单击响应,您就可以找到整个异常跟踪。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.