使用Pusher和Vue.js在Laravel聊天中出错500 Axios POST请求

时间:2018-05-05 13:44:50

标签: php laravel vue.js axios pusher

我在本教程中遇到问题,使用Pusher和Vue.js在Laravel中实现简单聊天:Link tutorial

我提出请求的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)

一切似乎都很好......有什么帮助吗?在此先感谢!!

0 个答案:

没有答案