web.php 的内容:
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
api.php 的内容:
Route::post('login', 'Api\UserController@login'); Route::post('register', 'Api\UserController@store');
Route::group(['middleware' => 'auth:api'], function () {
Route::group(['prefix' => 'posts'], function ()
{
Route::get('/', 'Api\PostController@index');
Route::post('/', 'Api\PostController@store');
Route::get('{post}', 'Api\PostController@show');
Route::put('{post}', 'Api\PostController@update');
Route::delete('{post}', 'Api\PostController@destroy');
Route::group(['prefix' => '{post}'], function ()
{
Route::group(['prefix' => 'comments'], function ()
{
Route::get('/', 'Api\CommentController@index');
Route::post('/', 'Api\CommentController@store');
});
});
});
Route::group(['prefix' => 'comments'], function ()
{
Route::get('{comment}', 'Api\CommentController@show');
Route::delete('{comment}', 'Api\CommentController@destroy')->middleware('role:Administrator');
});
Route::group(['prefix' => 'users', 'middleware' => 'role:Administrator'], function ()
{
Route::get('/', 'Api\UserController@index');
Route::post('/', 'Api\UserController@store');
Route::get('{user}', 'Api\UserController@show');
Route::put('{user}', 'Api\UserController@update');
Route::delete('{user}', 'Api\UserController@destroy');
}); });
Route::fallback(function() {
return response()->json(['message' => 'The requested page does not exist.'], 404); });
当我转到mysite.test / api / loginandsomeletters时,出现MethodNotAllowedHttpException,但是我希望得到NotFoundHttpException,因为这样的路由不存在。有人可以解释一下幕后发生的事情吗?