douzhan5262 2017-10-01 07:28
浏览 162
已采纳

使用Laravel中的绝对路径和wamp

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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码