Laravel 404未在API测试中找到

Laravel 404未在API测试中找到,laravel,postman,Laravel,Postman,我在Laravel做了我的API后端 我测试了Route::post('register','UserController@register'); 使用http://localhost/cloudengine-sandbox/cloudsandboxbackend/public/api/register 而且效果很好。 当我想测试短代码时,我遇到了一些问题 api.php Route::post('register','UserController@register'); 路由::post('l

我在Laravel做了我的API后端

我测试了
Route::post('register','UserController@register');
使用
http://localhost/cloudengine-sandbox/cloudsandboxbackend/public/api/register

而且效果很好。 当我想测试短代码时,我遇到了一些问题

api.php

Route::post('register','UserController@register');
路由::post('login','UserController@login');
路由::get('profile','UserController@getAuthenticatedUser');
路由::get('/shortcode','ShortcodeController@index')
->名称('shortcode.index');
路由::post('/shortcode','ShortcodeController@store')
->名称('shortcode.store');
路由::get('/shortcode/{shortcode}','ShortcodeController@show')
->名称('shortcode.show');
路由::put('/shortcode/{shortcode}','ShortcodeController@update')
->名称('shortcode.update');
路由::删除('/shortcode/{shortcode}','ShortcodeController@destroy')
->名称('shortcode.destroy');
我应该在邮递员中键入什么来测试每个短代码

我输入了
http://localhost/cloudengine-sandbox/cloudsandboxbackend/public/api/shortcodes/show


我希望可以,但给出了404 Not found

路由上的名称只是快捷方式,但当作为url访问它们时,您仍然需要使用定义的整个url

在您的示例中,url必须是:

http://localhost/cloudengine-sandbox/cloudsandboxbackend/public/api/shortcodes/{shortcode}

用数据库中短代码的有效id替换
{shortcode}


如果要为应用程序编写测试用例,请确保将
shortcode
绑定到
RouteServiceProvider
上的模型

.env
中设置应用程序url

APP_URL=http://web.local  //Any url that you  are using.
因为laravel使用
.env
中的
APP\u url
创建url

如果您正在使用POSTMAN进行测试


还要确保在POSTMAN中传递头
ACCEPT=application/json

在POSTMAN中传递get请求的参数是否正确?与Key:shortcode一样,value:show?发布控制器的show方法controller show方法:“公共函数show(shortcode$shortcode){return$shortcode;}”