无法在远程服务器上使用Laravel 5.1检索URL GET参数 [英] Can't retrieve url GET parameters with Laravel 5.1on remote server

查看:53
本文介绍了无法在远程服务器上使用Laravel 5.1检索URL GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我无法使用 Illuminate \ Http \ Request 门面从控制器中的URL获取任何GET参数.我在多个控制器上进行了测试,但没有成功.

For some reason I can't get any GET parameters from a url in my controllers using the Illuminate\Http\Request facade. I tested in multiple controllers, but no success.

使用以下代码,访问 domain.com/admin/dashboard?test=test 时,远程服务器上不返回任何内容,但是在我的本地计算机上,它返回 test :

Using the following code, nothing is returned on the remote server when accessing domain.com/admin/dashboard?test=test, but on my local machine it returns test:

The dashboard function is called by the route /admin/dashboard

/**
 * Dashboard page
 *
 * @return  view
 */
public function dashboard(Request $request)
{
    echo '<pre>';
    var_dump($request->all());
    echo '</pre>';

    // Return here
    return;

    // ...instead of here
    return view('backend::pages.dashboard');
}

我正在使用Nginx和php5-fpm在Ubuntu 14.04 LTS上运行Laravel 5.1.该代码在我的本地Homestead实例以及MAMP上都可以正常工作.我检查了我的Nginx配置,一切似乎都很好.我在服务器上托管了多个站点,并且可以在所有其他站点上获取路由参数.

I'm running Laravel 5.1 on Ubuntu 14.04 LTS using Nginx and php5-fpm. The code works fine on my local Homestead instance as well as on MAMP. I checked my Nginx configuration and everything seems fine. I'm hosting multiple sites on my server and I can get route parameters on all other sites.

推荐答案

如果有人遇到此问题,则问题出在我如何为此特定域设置Nginx.

If anyone runs into this, the problem was with how I set up Nginx for this particular domain.

我的/etc/nginx/sites-enabled/default 文件中的该块不适用于查询字符串:

This block in my /etc/nginx/sites-enabled/default file didn't work with query strings:

location / {
    try_files       $uri $uri/ /index.php$query_string;
}

将其更改为以下内容后,一切按预期进行:

After changing it to the following, everything worked as it supposed to be:

location / {
    try_files $uri $uri/ /index.php$is_args$args;
}

希望它对某人有帮助.

这篇关于无法在远程服务器上使用Laravel 5.1检索URL GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆