刚安装Lumen出现了NotFoundHttpException错误

15

我正在寻找解决方法...现在变得非常沮丧。 在使用Laravel的Lumen进行全新安装后,我无法访问“/”路由。每当我尝试访问它时,都会抛出错误:

NotFoundHttpException in RoutesRequests.php line 443:

in RoutesRequests.php line 443
at Application->handleDispatcherResponse(array('0')) in RoutesRequests.php line 380
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 629
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28

可能是Lumen安装错误的重复问题。 - patricus
1
无法再次投票。找到了一个更好的重复问题,其中包含更多的解释:https://dev59.com/d10a5IYBdhLWcg3w-8_a - patricus
4个回答

67

明白了!......

解决方法是在public/index.php的第28行进行更改:

$app->run();

$app->run($app->make('request'));

没有头绪为什么,也许你知道。


3
这解决了我在尝试将 Laravel 5 应用程序部署到生产环境时遇到的类似问题。我也很想知道为什么这样做可以解决问题。 - Nicole S.
我在使用IIS 8和Lumen时也遇到了同样的问题,但通过这种方法解决了它。 - Meisam Mulla
1
在我的本地MAMP上工作了...我觉得这很愚蠢。为什么会发生这种Bug/Feature? - AFX
3
仅有这一行文字写着“Lumen (5.5.2) (Laravel Components 5.5.*)”,对我并没有用。 - Anand Pandey
@AnandPandey 我也是一样。你找到解决方案了吗? - Anurag Shrivastava

3
这个问题可以通过更改代码来解决。
    $app->run();

/public/index.php 中到
    $request = Illuminate\Http\Request::capture();
    $app->run($request); 

3
我今天遇到了同样的问题。
我是通过以下url访问它的:http://localhost/lumen.api/public/,我认为这是错误的原因。
为了解决这个问题,我做了以下操作:
首先,在Xampp中配置了一个新的VirtualHost条目,我的情况下位于“C:\xampp\apache\conf\extra\httpd-vhosts.conf”:
<VirtualHost *:80>
    DocumentRoot "C:/xampp/htdocs/lumen.api/public"
    ServerName lumen.api
    ServerAlias www.lumen.api
    ErrorLog "logs/lumen.api-error.log"
    CustomLog "logs/lumen.api-access.log" common
    <Directory "C:/xampp/htdocs/lumen.api/public">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>

我在Xampp上重新启动了Apache。

然后,我编辑了我的hosts文件(c:\ windows \ system32 \ drivers \ etc \ hosts),将一个新的地址映射到我的本地主机。

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost   
    127.0.0.1       lumen.api

我再次尝试使用新的URL http://lumen.api,这次没有出现错误。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接