如何在laravel上自定义Route :: resource?

时间:2018-04-03 09:06:51

标签: php laravel laravel-5 routes resources

如果我的路线是这样的:

Route::prefix('member')->middleware('auth')->group(function(){
    Route::prefix('purchase')->group(function(){
        Route::get('order', 'Member\PurchaseController@order')->name('member.purchase.order');
        Route::get('transaction', 'Member\PurchaseController@transaction')->name('member.purchase.transaction');
    });
    Route::resource('purchase', 'Member\PurchaseController');
});

如果我致电:http://my-app.test/member/purchase/1,它就可以了。没有错误

但是我改变了这样的路线:

 Route::prefix('member')->middleware('auth')->group(function(){
    Route::prefix('purchase')->group(function(){
        Route::get('order', 'Member\PurchaseController@order')->name('member.purchase.order');
        Route::get('transaction', 'Member\PurchaseController@transaction')->name('member.purchase.transaction');
        Route::resource('/', 'Member\PurchaseController');
    });
 });

如果我致电:http://my-app.test/member/purchase/1,则会出现以下错误:

  

抱歉,找不到您要查找的页面。

我正在使用Laravel 5.6。 我该如何解决这个错误?

2 个答案:

答案 0 :(得分:0)

请试试这个:

 Route::prefix('member')->middleware('auth')->group(function(){
  Route::prefix('purchase')->group(function(){
  Route::resource('/', 'Member\PurchaseController');  
  Route::get('order', 'Member\PurchaseController@order')->name('member.purchase.order');
  Route::get('transaction', 'Member\PurchaseController@transaction')->name('member.purchase.transaction');   
  });
});

答案 1 :(得分:0)

php artisan api:route

在根文件夹中运行此命令。它会列出您定义的所有路线。使用资源检查显示哪条路线。