405(不允许使用方法)-Laravel和Vue.Js

时间:2020-06-16 14:26:18

标签: laravel vue.js

大家下午好,我正在尝试实施一个通知系统,并可能用类似的标记该通知。

我在后端使用laravel 7,在前端使用vuejs。

该代码可在localhost上正常工作,但是当我部署到Heroku时,它将停止工作,并在下面显示消息。

http://springalert.herokuapp.com/api/like 405 (Method Not Allowed)
Uncaught (in promise) Error: Request failed with status code 405
at createError (app.js:5347)
at settle (app.js:5608)
at XMLHttpRequest.handleLoad (app.js:4816)

有人对此主题有任何提示,我对此进行了研究,并且我知道我们必须配置CORS,但是对于此版本的laravel,据说不再需要。

遵循代码,谢谢您的帮助。

路线

Route::post('/api/like/', 'NotificationController@api_like');

控制器

public function api_like(Request $request) {
  $like = new Like;
  $like->notification_id = $request->id;
  $like->user_id = auth()->id();
  $like->save();
}

VUEJS

<b-card-text class="text-right" v-if="Object.keys(notification.like).length == 0">
   <a @click="makelike('success', 'Informação', notification.id)" class="a"><i class="fas fa thumbs-up"></i></a>
</b-card-text>
      makelike(variant = null, title, notification_id) {
        this.id = notification_id
        axios.post('api/like/',{ id:this.id })
                    .then((response) => {
                      this.set_notifications()
                      this.$bvToast.toast('Obrigado pela tua visualização', {
                        title: title,
                        variant: variant,
                        solid: true
                      })
                    })
      },

0 个答案:

没有答案