且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

错误500(内部服务器错误)ajax和laravel

更新时间:2022-03-23 23:03:37

看来我的(和 Anton's )预感是正确的。你有两条有冲突的路线。

It appears my(and Anton's) hunch was correct. You have two conflicting routes.

Route::post('comments/{post_id}', ['uses' => 'CommentsController@store', 'as' => 'comments.store']);

当然

Route::post('comments/', ['uses' => 'CommentsController@update', 'as' => 'comments.update']);

因为这两条路线大致使用相同的路线,所以laravel就是首先定义的,这是你的 comments.store 路线。

Because the two routes use roughly the same route, laravel just goes by which is defined first, which is your comments.store route.

有几种方法可以解决这个问题。

There are a couple ways to fix this.


  1. 更改路线的顺序:

  1. Change the order of your routes:

Route::post('comments/update', ['uses' => 'CommentsController@update', 'as' => 'comments.update']);
Route::post('comments/{post_id}', ['uses' => 'CommentsController@store', 'as' => 'comments.store']);
Route::get('comments/{id}/edit', ['uses' => 'CommentsController@edit', 'as' => 'comments.edit']);


  • 使用路线限制:

  • Use route constraints:

    Route::post('comments/{post_id}', [
        'uses' => 'CommentsController@store',
         'as' => 'comments.store'
    ])->where(['post_id' => '[0-9]+']);;
    Route::get('comments/{id}/edit', ['uses' => 'CommentsController@edit', 'as' => 'comments.edit']);
    Route::post('comments/update', ['uses' => 'CommentsController@update', 'as' => 'comments.update']);
    


  • 值得注意的是,我不知道如何Facade注册商处理外观方法的外壳(下部,上部)。因此,为了不引起进一步的错误,我使用 POST 的下部外壳,就像它一样在文档中使用。

    Of note, I don't know how the Facade registrar handles the casing(lower, upper) of facade methods.. So in an effort to not cause further bugs, I used the lower casing of POST, just as it is used in the documentation.