php - 使用 Pusher 和 Vue.js 在 Laravel 聊天中出现错误 500 Axios POST 请求
问题描述
我在本教程中使用 Pusher 和 Vue.js 在 Laravel 中实现简单聊天时遇到问题:链接教程。
我提出请求的 assets/js 中的 app.js 文件是这样的:
const app = new Vue({
el: '#app',
data: {
tweets: []
},
created() {
this.showTweets();
Echo.private('chat')
.listen('TweetSentEvent', (e) => {
this.tweets.push({
tweet: e.tweet.tweet,
user: e.user
});
});
},
methods: {
showTweets() {
axios.get('/tweets').then(response => {
this.tweets = response.data;
});
},
addTweet(tweet) {
this.tweets.push(tweet);
axios.post('tweets', tweet).then(response => {
console.log(response.data);
});
}
}
});
我的 web.php 路线:
Auth::routes();
Route::get('/', 'TweetController@index');
Route::get('tweets', 'TweetController@showTweets')-
>middleware('auth');
Route::post('tweets', 'TweetController@sentTweet
我的控制器是这个:
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('chat');
}
public function showTweets(){
return Tweet::with('user')->get();
}
public function sendTweet(Request $request){
$user = Auth::user();
$tweet = $user->tweets()->create([
'tweet' => $request->input('tweet')
]);
broadcast(new TweetSentEvent($user, $tweet))->toOthers();
//return ['status' => 'Tweet Sent!'];
}
当我运行应用程序并尝试通过单击我的发送按钮的 POST 请求发送推文时,此错误出现在控制台上:
POST http://localhost/youChat/public/tweets 500 (Internal Server Error)
Uncaught (in promise) Error: Request failed with status code 500
at createError (app.js:13931)
at settle (app.js:35401)
at XMLHttpRequest.handleLoad (app.js:13805)
一切似乎都很好......有什么帮助吗?提前致谢!!
解决方案
推荐阅读
- c# - c#用代码替换所有非ascii字符
- rust - 参考单元
> 不变 - c# - 报告在 stimul soft 上显示时更改查询
- excel-formula - 如何在excel中从右边每第二个数字后获取逗号..?
- reactjs - 如何设置 OrbitalControls 初始位置?
- flutter - Flutter compactCurrency 用于印度卢比,但需要用英文显示 lakhs, crores
- java - 堆栈 forEach 表达式以循环现有大小和新大小之间的差异
- python-3.x - 不使用 set_relationship_bound 和 like_by_feed 方法
- redmine - 在日志条目上更新计算的自定义字段(redmine)
- bash - 如何使用命令行检查是否安装了 c-blosc?