2017-10-01 07:28
浏览 147


I'm developing a Laravel project using wamp stack on windows. My project is located in a separate folder like C:\wamp64\www\[project name]. The annoying problem is with url paths in code. I want to handle them in a way that they work both locally and on production environment. For example this an absolute link:

<a href="/posts/tags/{{ $tag  }}">

It is intended to navigate user to [project name]/posts/... . In other words I want to get project root with a slash. If this is not possible, what is the correct way of handling paths then (on development and production environment). I'm a little confused with this. Please provide detailed information considering both WAMP and Laravel. And please give information about relative paths, too.

图片转代码服务由CSDN问答提供 功能建议

我正在使用Windows上的wamp堆栈开发一个Laravel项目。 我的项目位于单独的文件夹中,例如 C:\ wamp64 \ www \ [项目名称] 。 恼人的问题是代码中的url路径。 我想以他们在本地和生产环境中工作的方式处理它们。 例如这是一个绝对链接:

 &lt; a href =“/ posts / tags / {{$ tag}}”&gt; 

它旨在将用户导航到 [项目名称] / posts /... 。 换句话说,我想用斜杠获取项目根目录。 如果这是不可能的,那么处理路径的正确方法是什么(在开发和生产环境中)。 我对此有点困惑。 请提供考虑WAMP和Laravel的详细信息。 请提供有关相对路径的信息。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtdvbf37193 2017-10-01 10:18

    So what I finally did was to use the suggested method by @iCoders plus having APP_URL set in .env file to http://localhost/[project_name]/public. This way url method resolves the correct path provided that your config/app.php contains 'url' => env('APP_URL', 'http://localhost') and you make the URL generator use APP_URL. For more information, check this link: Laravel: Change base URL? To differentiate development and production environments different .env files can be used for each.

    解决 无用
    打赏 举报
  • dongzaheng4449 2017-10-01 07:38

    You can use url method url method will return base url

    <a href="{{url('/posts/tags/'.$tag)}}">edit tag</a>


    The url function generates a fully qualified URL to the given path

    解决 无用
    打赏 举报

相关推荐 更多相似问题