skip to Main Content

I have this extremely simple code snipped in my controller, which always did its job of getting a php varaible from URL:
URL: wholesaleeventeditions/create?event=36

    $wholesaleevent = Input::get('event');
    if(isset($wholesaleevent)) {
        $event = $wholesaleevent;
    } else {
        $event = null;
    }

Now, after I have migrated to new VPS service, Laravel 8 cannot handle the variable. It must be server problem, as my obsolete app build on Laravel 5.8 started to produce similar effect.

My environments:

  • LOCAL: Windows 10, php 7.4.13 vc 15 TS, Laravel 8 and Laravel 5.8, Apache 2.4.46 VS16 (on newest Laragon 5.0)
  • REMOTE: Ubuntu 20.10, Nginx 1.18.0, php 7.4.9
  • A Laravel version note: Mu best guess is that it must be something with the Ubuntu 20.10 server config, as the error broke down a separate Laravel 5.8 app of mine. I have no clue though I would blame a quirk in php 7.4.

What I tried but to no avail:

  • In desperation, I changed $input = Input::get('event'); to $input = Input::all(); and then $event = $wholesaleevent['event'];. The code works on local, but on remote server it produces `Undefined index: event’ error.
  • I have disabled SSL protection in my server (and rebooted the server to make sure no caches interfere). In other words: I have changed server to http only and accessed it with a separate browser by typing url containing http only.

2

Answers


  1. $wholesaleevent = $input = Input::all();
    if (isset($wholesaleevent['event'])) {
       $event = $wholesaleevent;
    } else {
       $event = null;
    }
    

    or

    $wholesaleevent = $input = Input::get('event', false);
    if (!empty($wholesaleevent)) {
       $event = $wholesaleevent;
    } else {
       $event = null;
    }
    
    Login or Signup to reply.
  2. If you have an error in both of your Laravels, then it is a NGINX misconfiguration.

    This is the most basic config for it, see if you are missing anything:

    server {
        listen 80;
    
        index index.php;
    
        error_log  /var/log/nginx/error.log;
        access_log /var/log/nginx/access.log;
    
        root /var/www/public;
    
        location ~ .php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+.php)(/.+)$;
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
        }
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
            gzip_static on;
        }
    }
    

    Also, a small tip for your code: If you are not using the value again (you stored it at $event), you can do this to have better code:

    $event = Input::get('event');
    

    get has a second parameter that, by default, is null. That parameter will be the default value if 'event' is not present in the URI. Also, try always to use Request ($request) and not plain Input.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search