7

I am working on a Laravel project and am trying to get GET parameters from a controller. Requesting a page with ?date={value} should return value as follows:

public function getIndex(Request $request) {
    return $request->input("date");
}

This does not work though. POST requests work as they should. I am using nginx through cloudflare. I tried making a plain PHP file with

echo $_GET["date"];

which works fine.

Streetlamp
  • 1,537
  • 2
  • 15
  • 27
  • Just to be clear, this parameter that you want is been passed as a query string? – Victor Aug 10 '15 at 19:12
  • @Victor Yes, that is correct – Streetlamp Aug 10 '15 at 19:13
  • What version of laravel are you using? 4.2, 5.0 or 5.1? What does your route that call that Method looks like? See if [this response](https://stackoverflow.com/questions/24744825/laravel-queries-strings) helps you. – Victor Aug 10 '15 at 19:17
  • @Victor I am using version 5.0. `Input::get("date")` does not work either. In routes.php I have `Route::controller('page', 'PageController');`. – Streetlamp Aug 10 '15 at 19:40
  • 1
    is this a copy of this question? http://stackoverflow.com/questions/31923484/cant-retrieve-get-variables-in-laravel/31927415#31927415 it is very identical – Maytham Fahmi Aug 10 '15 at 20:54
  • @maytham None of the answers worked for me – Streetlamp Aug 11 '15 at 00:00

3 Answers3

18

I found my problem. In the nginx configuration for the site (/etc/nginx/sites-available/default), I had

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

which should be

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

Fixed, restarted, now it works.

Streetlamp
  • 1,537
  • 2
  • 15
  • 27
2

My problem was in .htaccess file after remove index.php from url , just add this simple code in .htaccess file :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
0

Maybe getIndex() and Request $request dont work with Route::controller. Use a get('/my-route'), It's more flexible.