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

使用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条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵