我正在使用Laravel创建一个api,我正在寻找一种简单的惰性方法来注册Api资源。我目前正在定义这样的路线:
Route::apiResoruce('categories', 'CategoryController')->only(['index', 'show']);
我检查了Laravel's controller documentation,看到了apiResources
方法,可以立即创建多个api资源。
目标:才能将apiResources
与only
方法一起使用,例如这样
Route::apiResources(['categories' => 'CategoryController', 'products' => 'ProductController'])->only(['index', 'show']);
当前结果:
Call to a member function only() on null
长话短说(如果您不想阅读整个故事),您可以这样做: