干净的Laravel 5.1使用获取NotFoundHttpException的单个RESTful路由进行安装 [英] Clean Laravel 5.1 Install with a single RESTful route getting NotFoundHttpException

查看:137
本文介绍了干净的Laravel 5.1使用获取NotFoundHttpException的单个RESTful路由进行安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5作为Ionic应用程序的API,它似乎几乎可以正常工作,但是我在Laravel中进行测试的路线

I'm using Laravel 5 as an API for an Ionic app, and it appears to be almost working, but my test route in Laravel

Route::group( [ 'prefix' => 'api' ], function ()
{
    Route::any( 'user', function ()
    {
        return 'Hello Anonymous User';
    } );
} );

当我点击

http://localhost:8000/api/user

应该只返回"Hello Anonymous User",但由于切换到Homestead而不是使用工匠服务,它现在会引发以下错误:

Should just return "Hello Anonymous User", but since switching to Homestead instead of using artisan serve it now throws this error:

Sorry, the page you are looking for could not be found.

NotFoundHttpException in RouteCollection.php line 145:
in RouteCollection.php line 145
at RouteCollection->match(object(Request)) in Router.php line 719
at Router->findRoute(object(Request)) in Router.php line 642
at Router->dispatchToRoute(object(Request)) in Router.php line 618
at Router->dispatch(object(Request)) in Kernel.php line 210
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 111
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53

任何从Ionic使用ngResource到API的帖子都会在控制台中作为500 Error返回.我发现一种解决方案建议通过注释掉app/http/Kernel.php中的VerifyCsrfToken中间件:

And any post from Ionic using ngResource to the API is returned as a 500 Error in the console. I found one solution that suggested turning off VerifyCsrfToken middleware in app/http/Kernel.php by commenting out:

\App\Http\Middleware\VerifyCsrfToken::class,

但这无法正常工作或更改错误.

but this didn't work or change the error.

我可以在 http://localhost:8000/上找到默认的欢迎路线,并查看Laravel 5欢迎使用debugbar查看.我还尝试仅使用上面没有组的内部路由表单,然后点击 http://localhost:8000/user ,但它会产生相同的错误.

I am able to hit the default welcome route at http://localhost:8000/ and see the Laravel 5 welcome view with debugbar. I also tried using just the inner route form above without the group and hit http://localhost:8000/user, but it produces the same error.

更新

检查路线列表,发现所有路线都可以.

Checking the route list all the routes appear to be okay.

php artisan route:list

| GET|HEAD                       | /                 | Closure
| GET|HEAD|POST|PUT|PATCH|DELETE | api/user          | Closure
| GET|HEAD|POST|PUT|PATCH|DELETE | user              | Closure

... with debugbar routes

推荐答案

如果它与工匠服务而不是宅基地一起使用,则您的宅基地主机设置可能会将您的请求发送到宅基地上的默认项目,而不是将请求发送到宅基地上的默认项目你已经设置好了.请确认路径文件顶部的dd("ping")显示在屏幕上.否则,您可能会看错应用程序.

If it works with artisan serve instead of homestead then it is likely that your homestead hosts setup is sending your request to the default project on homestead instead of the one that you have setup. Please confirm that dd("ping") at the top of your routes file shows up on screen. Otherwise, you are likely looking at the wrong app.

检查计算机上的/etc/hosts文件(假设OS X或* nix),并确保已设置192.168.10.10指向someappname.app,并在〜/.homestead/Homestead.yaml中确保在网站:您添加的部分中

Check your /etc/hosts file on your machine (assuming OS X or *nix) and make sure you've setup 192.168.10.10 to point to someappname.app and in your ~/.homestead/Homestead.yaml make sure in the sites: section you have added

-map: someappname.app
 to: /home/whatever the mapped path to this app is

在〜/Homestead目录中,输入vagrant规定以确保vagrant占用了最新的更改.

From within your ~/Homestead directory, type vagrant provision to make sure vagrant takes up the latest changes.

我认为这应该可以解决您的问题.

I think this should solve your problem.

这篇关于干净的Laravel 5.1使用获取NotFoundHttpException的单个RESTful路由进行安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆