【问题标题】:How to run the show method in routes.php如何在 routes.php 中运行 show 方法
【发布时间】:2020-08-03 10:19:23
【问题描述】:

我在 routes.php 中写下这条路线:

Route::post('reserves', 'Test\Api\Controllers\Reserves@index');
Route::post('reserves/{id}', 'Test\Api\Controllers\Reserves@show');

当我的网址是:

site.local/api/v1/reserves

index 方法可以正常运行,但是当我使用这个带有 userId 参数的 url 而不是运行 show 方法时 index 方法运行,我该如何修复它?

site.local/api/v1/reserves // with userId parameters

【问题讨论】:

  • 您的意思是site.local/api/v1/reserves/2 运行index 方法? (顺便说一句,香草 Laravel 中没有 routes.php

标签: laravel url post methods routes


【解决方案1】:

尝试get方法而不是post方法:

Route::get('reserves/{id}', 'Test\Api\Controllers\Reserves@show');

【讨论】:

    【解决方案2】:

    你是如何传递你的用户 ID 参数的?为了运行show,您应该使用以下网址:

    site.local/api/v1/reserves/1 //or 1 replaced with any other id
    

    如果您将用户ID 作为GETPOST 参数传递,则不会执行show 方法。

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 2016-06-20
      相关资源
      最近更新 更多