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

报告相同问题?