Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Pusher和Vue.js在Laravel聊天中发出500 Axios POST请求时出错_Php_Laravel_Vue.js_Axios_Pusher - Fatal编程技术网

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

Php 使用Pusher和Vue.js在Laravel聊天中发出500 Axios POST请求时出错,php,laravel,vue.js,axios,pusher,Php,Laravel,Vue.js,Axios,Pusher,在本教程之后,使用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

在本教程之后,使用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);
    });
}
}
});
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!'];

}
My web.php路由:

Auth::routes();
Route::get('/', 'TweetController@index');
Route::get('tweets', 'TweetController@showTweets')- 
>middleware('auth');
Route::post('tweets', 'TweetController@sentTweet
我的控制器是这个:

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);
    });
}
}
});
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)

一切似乎都很好。。。有什么帮助吗?提前谢谢

也请共享您的api路由。Auth::routes();路由::获取('/','TweetController@index'); 路由::获取('tweets','TweetController@showTweets')->中间件('auth');路由::post('tweets','TweetController@sentTweet“给你,谢谢!