我的一些Laravel路线(PUT和DELETE)不能在共享主机上工作

时间:2015-02-16 13:06:14

标签: php laravel url-routing laravel-routing

我使用Laravel开发了一个Web应用程序。在我当地的开发环境和专用服务器上,一切都很好。但当我切换到共享主机(OVH)时,当我尝试更新或删除资源时,Laravel会返回MethodNotAllowedHttpException。 HTTP GETPOST请求效果很好。

我不知道我的主持人是否允许GETPOST以外的请求。但实际上问题不存在(我认为):因为Laravel使用POST请求来模拟" PUTDELETE请求(输入类型为隐藏" _method")。所以我不认为这是问题。

我需要你的帮助才能找到问题所在。 我不明白为什么我的路线在开发环境中工作,并且(我的某些路线)不能在我的共享主机上工作。

没有意义!

您是否需要其他信息(可能是php.ini?)


修改

我的routes.php文件(这些路由在WAMP或我的专用服务器上都可以):

// Backend
Route::group(['prefix' => 'admin', 'namespace' => 'Controllers\Backend', 'before' => 'auth.wordpress'], function() {

    Route::get('/', 'DashboardController@index');

    Route::get('products/{status}', ['as' => 'admin.products.index.status', 'uses' => 'ProductsController@index'])->where('status', 'publish|draft|featured');
    Route::post('products/index', ['as' => 'admin.products.filter', 'uses' => 'ProductsController@index']);
    Route::resource('products', 'ProductsController');

    Route::post('categories/index', ['as' => 'admin.categories.filter', 'uses' => 'CategoriesController@index']);
    Route::resource('categories', 'CategoriesController');

    Route::post('manufacturers/index', ['as' => 'admin.manufacturers.filter', 'uses' => 'ManufacturersController@index']);
    Route::resource('manufacturers', 'ManufacturersController');

    Route::post('attributes/index', ['as' => 'admin.attributes.filter', 'uses' => 'AttributesController@index']);
    Route::resource('attributes', 'AttributesController');

    Route::resource('upload', 'UploadController', ['only' => array('store', 'destroy')]);
    Route::post('upload/{from}', ['as' => 'admin.upload.store.from', 'uses' => 'UploadController@store']);

});
php artisan routes命令生成的

路由

+--------+---------------------------------------------------+-------------------------------------+-----------------------------------------------------------+----------------+---------------+
| Domain | URI                                               | Name                                | Action                                                    | Before Filters | After Filters |
+--------+---------------------------------------------------+-------------------------------------+-----------------------------------------------------------+----------------+---------------+
|        | GET|HEAD /                                        |                                     | Closure                                                   |                |               |
|        | GET|HEAD products/featured                        | frontend.products.featured          | Controllers\Frontend\ProductsController@featured          |                |               |
|        | GET|HEAD products/sidebar/{slugCategory?}         | frontend.products.sidebar           | Controllers\Frontend\ProductsController@sidebar           |                |               |
|        | GET|HEAD products/last                            | frontend.products.last              | Controllers\Frontend\ProductsController@last              |                |               |
|        | POST products/search/{page?}                      | frontend.products.search            | Controllers\Frontend\ProductsController@search            |                |               |
|        | GET|HEAD products/show/{slug}                     | frontend.products.show              | Controllers\Frontend\ProductsController@show              |                |               |
|        | GET|HEAD products/show/{slug}/meta                | frontend.products.show.meta         | Controllers\Frontend\ProductsController@showMeta          |                |               |
|        | GET|POST|HEAD products/{category?}/{page?}        | frontend.products.show              | Controllers\Frontend\ProductsController@index             |                |               |
|        | GET|HEAD categories/show/{category}/meta          | frontend.categories.meta            | Controllers\Frontend\ProductsController@categoryMeta      |                |               |
|        | GET|HEAD manufacturers/listHomepage               | frontend.manufacturers.listHomepage | Controllers\Frontend\ManufacturersController@listHomepage |                |               |
|        | GET|HEAD manufacturers                            | frontend.manufacturers.index        | Controllers\Frontend\ManufacturersController@index        |                |               |
|        | GET|HEAD manufacturers/{slug}                     | frontend.manufacturers.show         | Controllers\Frontend\ManufacturersController@show         |                |               |
|        | GET|HEAD manufacturers/{slug}/meta                | frontend.manufacturers.show.meta    | Controllers\Frontend\ManufacturersController@showMeta     |                |               |
|        | GET|HEAD admin                                    |                                     | Controllers\Backend\DashboardController@index             | auth.wordpress |               |
|        | GET|HEAD admin/products/{status}                  | admin.products.index.status         | Controllers\Backend\ProductsController@index              | auth.wordpress |               |
|        | POST admin/products/index                         | admin.products.filter               | Controllers\Backend\ProductsController@index              | auth.wordpress |               |
|        | GET|HEAD admin/products                           | admin.products.index                | Controllers\Backend\ProductsController@index              | auth.wordpress |               |
|        | GET|HEAD admin/products/create                    | admin.products.create               | Controllers\Backend\ProductsController@create             | auth.wordpress |               |
|        | POST admin/products                               | admin.products.store                | Controllers\Backend\ProductsController@store              | auth.wordpress |               |
|        | GET|HEAD admin/products/{products}                | admin.products.show                 | Controllers\Backend\ProductsController@show               | auth.wordpress |               |
|        | GET|HEAD admin/products/{products}/edit           | admin.products.edit                 | Controllers\Backend\ProductsController@edit               | auth.wordpress |               |
|        | PUT admin/products/{products}                     | admin.products.update               | Controllers\Backend\ProductsController@update             | auth.wordpress |               |
|        | PATCH admin/products/{products}                   |                                     | Controllers\Backend\ProductsController@update             | auth.wordpress |               |
|        | DELETE admin/products/{products}                  | admin.products.destroy              | Controllers\Backend\ProductsController@destroy            | auth.wordpress |               |
|        | POST admin/categories/index                       | admin.categories.filter             | Controllers\Backend\CategoriesController@index            | auth.wordpress |               |
|        | GET|HEAD admin/categories                         | admin.categories.index              | Controllers\Backend\CategoriesController@index            | auth.wordpress |               |
|        | GET|HEAD admin/categories/create                  | admin.categories.create             | Controllers\Backend\CategoriesController@create           | auth.wordpress |               |
|        | POST admin/categories                             | admin.categories.store              | Controllers\Backend\CategoriesController@store            | auth.wordpress |               |
|        | GET|HEAD admin/categories/{categories}            | admin.categories.show               | Controllers\Backend\CategoriesController@show             | auth.wordpress |               |
|        | GET|HEAD admin/categories/{categories}/edit       | admin.categories.edit               | Controllers\Backend\CategoriesController@edit             | auth.wordpress |               |
|        | PUT admin/categories/{categories}                 | admin.categories.update             | Controllers\Backend\CategoriesController@update           | auth.wordpress |               |
|        | PATCH admin/categories/{categories}               |                                     | Controllers\Backend\CategoriesController@update           | auth.wordpress |               |
|        | DELETE admin/categories/{categories}              | admin.categories.destroy            | Controllers\Backend\CategoriesController@destroy          | auth.wordpress |               |
|        | POST admin/manufacturers/index                    | admin.manufacturers.filter          | Controllers\Backend\ManufacturersController@index         | auth.wordpress |               |
|        | GET|HEAD admin/manufacturers                      | admin.manufacturers.index           | Controllers\Backend\ManufacturersController@index         | auth.wordpress |               |
|        | GET|HEAD admin/manufacturers/create               | admin.manufacturers.create          | Controllers\Backend\ManufacturersController@create        | auth.wordpress |               |
|        | POST admin/manufacturers                          | admin.manufacturers.store           | Controllers\Backend\ManufacturersController@store         | auth.wordpress |               |
|        | GET|HEAD admin/manufacturers/{manufacturers}      | admin.manufacturers.show            | Controllers\Backend\ManufacturersController@show          | auth.wordpress |               |
|        | GET|HEAD admin/manufacturers/{manufacturers}/edit | admin.manufacturers.edit            | Controllers\Backend\ManufacturersController@edit          | auth.wordpress |               |
|        | PUT admin/manufacturers/{manufacturers}           | admin.manufacturers.update          | Controllers\Backend\ManufacturersController@update        | auth.wordpress |               |
|        | PATCH admin/manufacturers/{manufacturers}         |                                     | Controllers\Backend\ManufacturersController@update        | auth.wordpress |               |
|        | DELETE admin/manufacturers/{manufacturers}        | admin.manufacturers.destroy         | Controllers\Backend\ManufacturersController@destroy       | auth.wordpress |               |
|        | POST admin/attributes/index                       | admin.attributes.filter             | Controllers\Backend\AttributesController@index            | auth.wordpress |               |
|        | GET|HEAD admin/attributes                         | admin.attributes.index              | Controllers\Backend\AttributesController@index            | auth.wordpress |               |
|        | GET|HEAD admin/attributes/create                  | admin.attributes.create             | Controllers\Backend\AttributesController@create           | auth.wordpress |               |
|        | POST admin/attributes                             | admin.attributes.store              | Controllers\Backend\AttributesController@store            | auth.wordpress |               |
|        | GET|HEAD admin/attributes/{attributes}            | admin.attributes.show               | Controllers\Backend\AttributesController@show             | auth.wordpress |               |
|        | GET|HEAD admin/attributes/{attributes}/edit       | admin.attributes.edit               | Controllers\Backend\AttributesController@edit             | auth.wordpress |               |
|        | PUT admin/attributes/{attributes}                 | admin.attributes.update             | Controllers\Backend\AttributesController@update           | auth.wordpress |               |
|        | PATCH admin/attributes/{attributes}               |                                     | Controllers\Backend\AttributesController@update           | auth.wordpress |               |
|        | DELETE admin/attributes/{attributes}              | admin.attributes.destroy            | Controllers\Backend\AttributesController@destroy          | auth.wordpress |               |
|        | POST admin/upload                                 | admin.upload.store                  | Controllers\Backend\UploadController@store                | auth.wordpress |               |
|        | DELETE admin/upload/{upload}                      | admin.upload.destroy                | Controllers\Backend\UploadController@destroy              | auth.wordpress |               |
|        | POST admin/upload/{from}                          | admin.upload.store.from             | Controllers\Backend\UploadController@store                | auth.wordpress |               |
+--------+---------------------------------------------------+-------------------------------------+-----------------------------------------------------------+----------------+---------------+

phpinfo(): https://www.dropbox.com/s/mj7d6c6ptdj9i4u/phpinfo_ovh.png?dl=0

错误的Stacktrace:

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException thrown with message ""

Stacktrace:
#13 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /home/guicara/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:210
#12 Illuminate\Routing\RouteCollection:methodNotAllowed in /home/guicara/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:197
#11 Illuminate\Routing\RouteCollection:getOtherMethodsRoute in /home/guicara/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:145
#10 Illuminate\Routing\RouteCollection:match in /home/guicara/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1049
#9 Illuminate\Routing\Router:findRoute in /home/guicara/vendor/laravel/framework/src/Illuminate/Routing/Router.php:1017
#8 Illuminate\Routing\Router:dispatchToRoute in /home/guicara/vendor/laravel/framework/src/Illuminate/Routing/Router.php:996
#7 Illuminate\Routing\Router:dispatch in /home/guicara/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:775
#6 Illuminate\Foundation\Application:dispatch in /home/guicara/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:745
#5 Illuminate\Foundation\Application:handle in /home/guicara/vendor/laravel/framework/src/Illuminate/Session/Middleware.php:72
#4 Illuminate\Session\Middleware:handle in /home/guicara/vendor/laravel/framework/src/Illuminate/Cookie/Queue.php:47
#3 Illuminate\Cookie\Queue:handle in /home/guicara/vendor/laravel/framework/src/Illuminate/Cookie/Guard.php:51
#2 Illuminate\Cookie\Guard:handle in /home/guicara/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23
#1 Stack\StackedHttpKernel:handle in /home/guicara/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:641
#0 Illuminate\Foundation\Application:run in /home/guicara/www/public/index.php:61

编辑2

共享主机(OVH)上的Firebug调试: Firebug debug on the shared hosting

WAMP(本地)上的Firebug调试...针对相同的请求(更新产品): Firebug debug on WAMP (local)

1 个答案:

答案 0 :(得分:-2)

我认为很清楚发生了什么。 您为 POST GET 设置路线,但期望 DELETE PUT 进行神奇的路由。

Route::delete('attributes/destroy/{id}','AttributesController@destroy');
Route::put('products/{id}', 'ProductsController@update');

最好的方法是隐式路由所有内容。