Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't retrieve url GET parameters with Laravel 5.1on remote server

Tags:

php

nginx

laravel

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.

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');
}

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.

like image 329
noodles_ftw Avatar asked Aug 22 '15 08:08

noodles_ftw


2 Answers

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

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;
}

Hope it helps someone.

like image 104
noodles_ftw Avatar answered Nov 14 '22 16:11

noodles_ftw


Try to access it like this:

$var = Input::get('test');

Here is how to do it: Retrieving GET and POST data inside controller in Laravel 4 And also here: What's the best practice accessing $_GET values in Laravel?

Hope helps

like image 1
user1870556 Avatar answered Nov 14 '22 15:11

user1870556