$request not working on laravel get method

Viewed 5455

I have a route

Route::get('student-search', 'Students@search')

and url on browser

student-search?session=2&name=raj&grade=1&section=a

But while returning $request its returning empty . Same thing is working fine on local but not working after trnsferring it to server.

code of search function looks like this

public function search(Request $request){
        return $request;
...

and $request returns empty . While same thing is working on localhost.

2 Answers

What you are missing is your server is not passing query parameter in any form of request. If you are using nginx try

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

Try this code:-

use Illuminate\Http\Request; // add this in top controller
public function search(Request $request) {
    $data = $request->all();
    echo "<pre>"; print_r($data);
}

   ------OR--------

use Request; // add this in top controller
public function search() {
    $data = Request::all();
    echo "<pre>"; print_r($data);
}

Hope it helps

Related