Php 不允许使用axios立柱405 | Laravel和#x2B;vue.js

Php 不允许使用axios立柱405 | Laravel和#x2B;vue.js,php,laravel,vue.js,post,axios,Php,Laravel,Vue.js,Post,Axios,我不能创建新的数据库记录,因为提交后它总是显示POST 405(不允许)。我试图将laravel路由从api.php移动到web.php,但没有成功。还尝试修改axios.post链接(创建、/create、,localhost://Reservationsystem/public/create)但它也没有给我结果 Web.php Route::resource('/reservation','ReservationController'); Route::get('/{any}', 'Sing

我不能创建新的数据库记录,因为提交后它总是显示POST 405(不允许)。我试图将laravel路由从api.php移动到web.php,但没有成功。还尝试修改axios.post链接(创建、/create、,localhost://Reservationsystem/public/create)但它也没有给我结果

Web.php

Route::resource('/reservation','ReservationController');
Route::get('/{any}', 'SinglePageController@index')->where('any', '.*');
Routes.js

import Vue from 'vue'
import Router from 'vue-router'
import Home from './components/HomeComponent.vue'
import Reservations from './components/ReservationsComponent.vue'

Vue.use(Router);

export default new Router({
    routes: [
        {
            path: '/',
            name: 'home',
            component: Home
        },
        {
            path: '/reservations',
            name: 'reservations',
            component: Reservations
        }
    ]
})
HomeComponent.vue

<script>
    import axios from 'axios';

    export default {
        data: function () {
            return {
                reservation: {
                    name: '',
                    surname: '',
                    email: '',
                    date: '',
                    place: ''
                }
            }
        },
        methods: {
            addReservation: function () {
                let uri = 'reservation';
                axios.post(uri, this.reservation).then(res => this.reservation = [...this.reservation, res.data]);
            }
        }
    }
</script>

您可能会得到405的原因是,在addReservation方法中,路线不是Post以与Post一致。对于Post路线,我将使用以下方法:

Route::post('/reservation/store','ReservationController@store');
对于axios中的uri,我将使用:

let uri = 'reservation/store';
这里有一个链接,显示了我是如何将axios与Laravel一起使用的。

您可能获得405的原因是,在addReservation方法中,路线与Post不一致。对于Post路线,我将使用以下方法:

Route::post('/reservation/store','ReservationController@store');
对于axios中的uri,我将使用:

let uri = 'reservation/store';
这里有一个链接,显示了我是如何将axios与Laravel一起使用的。
你使用https吗?如果是,请不要在地址末尾使用
/

您使用https吗?如果是,请不要在地址末尾使用
/

请在控制器中包含代码。你们有公共功能商店吗?有。现在添加方法,尝试离开路由
route::resource('/reservation','ReservationController')api.php
中编写>并对
/api/reservation
url进行axios调用。进行调用时,请检查网络选项卡。调用的完整url是什么(在“网络”选项卡中)?当我尝试访问post方法url时,它会显示空白页,这很奇怪,经过一些研究,我发现在url中公开后,我需要添加index.php(localhost/project/public/index.php/…),这似乎是服务器配置问题。请在控制器中包含代码。你们有公共功能商店吗?有。现在添加方法,尝试离开路由
route::resource('/reservation','ReservationController')api.php
中编写>并对
/api/reservation
url进行axios调用。进行调用时,请检查网络选项卡。调用的完整url是什么(在“网络”选项卡中)?当我尝试访问post方法url时,它会显示一个空白页面,这很奇怪,经过一些研究,我发现在url中公开后,我需要添加index.php(localhost/project/public/index.php/…),这似乎是服务器配置问题。。