浏览器里的 route () 函数运行结果与 tinker 中的不一致?

由于电脑内存小,开多了应用非常卡顿,所以将homestead里面的应用移植到了本机,也配置了域名解析,域名为larashop.com   
修改.env的配置APP_URL=http://larashop.com

当访问相关页面时来解析代码route('products.show', $product->id)
blade模板解析出来是 http://localhost:8001/products/1
tinker中解析出来是 http://larashop.com/products/1

我尝试过清除配置和视图之类的缓存,但是都不解决问题,不知道是不是我漏了什么,请大神指点下!

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 9

为什么说是浏览器解析出来不是太懂,而且我感觉route()函数只是生成了/products/1这个部分然后使用当前的域名进行重定向。

4年前 评论

@ddingchen 浏览器解析的意思就是route()函数在blade模版引擎中解析到的结果{{ route('products.show', id) }},我在chrome调试工具里查看源码看到的是localhost:8001 而不是我设置好的域名larashop.com

4年前 评论

额我觉得这个配置的理解上你可能有些误解,看一下官方代码注释,这个配置就是为了console环境设定的。我还是觉得应该不是代码问题,应该是Web服务器之类的环境问题,或者不清楚你是不是因为访问的时候就是用的 localhost:8001 来访问站点所以导致这样的现象。

/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/

'url' => env('APP_URL', 'http://localhost'),
4年前 评论

浏览器只是渲染一个页面,并不会解析任何东西

4年前 评论

@Kevinvinvin 访问是用的域名 larashop.com 来访问,根据你的说法,好像确实是那个配置是为console设定的.如果是和环境配置的原因,这是我nginx的配置信息,而且我查看了homestead里面的环境配置,好像没多大的区别!

server {
        listen 8001; #default_server;
        #listen [::]:8001 default_server ipv6only=on;

        root /home/airmy/laravel/laravel-shop/public;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name larashop.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?$args;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        # location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8001;    
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/html;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

                # With php5-cgi alone:
                # fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}
4年前 评论

我看到你问题中写的网址是http://larashop.com/products/1,但是服务器配置里写的监听的是listen 8001端口,所以难道不是应该http://larashop.com:8001/products/1这样访问嘛,还是说只是你问题里没写全端口。

4年前 评论

检查下你请求的网址

4年前 评论

@FMW @Kevinvinvin 请求的是本地localhost:8001 但是配置了域名解析域名是larashop.com,所以我是直接请求http://www.larashop.com 就行了.可能是我没怎么描述清楚,可以看看这个https://github.com/laravel/framework/issues/18613

4年前 评论
server {
    listen 8001;
    server_name larashop.com;
}

如果是这样的配置,那访问这个server就得http://larashop.com:8001这样访问。我不确定这一点你是不是误解了。

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!