【问题标题】:Laravel route exist but unable to view pageLaravel 路由存在但无法查看页面
【发布时间】:2020-12-08 04:25:50
【问题描述】:

我被邀请参与一个 laravel 7 项目,我已经能够使用 wamp 服务器在 Windows 10 系统上本地设置该项目。在审查项目时,我注意到计划是使用子域路由。我目前的任务是设置刀片模板,我想测试路线,但即使路线存在,我也无法让路线正常工作。这就是路线的样子

当我尝试通过调用realestate.localhost:8000 之类的 url 查看房地产页面时,我收到以下连接错误

路由在routes/realestate.php 文件夹内,并且使用了闭包

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return 'Realestate Routes';
});

在我的本地环境中调用路由的正确方法是什么?

【问题讨论】:

  • 那不是Laravel,你错误配置了服务器,域没有指向laravel项目
  • 您的计算机如何知道这些域(子域)指向的主机?
  • @Berto99 这是在我的开发环境中,而不是在实时服务中。我可以使用 http://localhost:8000 进入欢迎页面,但在尝试获取 http://realestate.localhost:8000 时遇到问题
  • @lagbox 我不知道因此我发布问题的原因。
  • 明白了,我可能在想类似“主机”文件的东西

标签: php laravel


【解决方案1】:

您需要编辑您的主机并从您的子域添加到 localhost 的重定向。见https://stackoverflow.com/a/56921347/11775360

【讨论】:

    【解决方案2】:

    我不确定您的环境是否与我的不同,但请确保您通过 http:// 而不是 https:// 访问

    我刚刚看到您的路线代码 - 辛苦了一天,抱歉 :P 尝试阅读子域路由here

    您的路线应如下所示:

    Route::domain('realestate.localhost')->group(function () {
        Route::get('/', function () {
            return 'Hello, world!'
        });
        
        // all other routes for realestate.localhost go in here
    });
    

    【讨论】:

    • 我像http://realestate.localhost:8000一样通过http访问,但没有成功。但是我可以使用http://localhost:8000 进入主页
    • 刚刚为您更新了我的答案!抱歉,我之前没有看到您的路线代码。 :P
    猜你喜欢
    • 1970-01-01
    • 2018-02-12
    • 2018-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多