Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Laravel REST controller $request->input is NULL?

I am following tutorial http://www.tutorials.kode-blog.com/laravel-5-angularjs-tutorial and I have managed to write the similar method for my controller:

public function update(Request $request, $id) {
    $employee = Employee::find($id);

    $employee->name = $request->input('name');
    //...
    $employee->save();

    return "Sucess updating user #" . $employee->id;
}

It is thought in tutorial that this code works but in reality var_dump($request->input) gives NULL. So - what $request variable should I use for getting the body of the request? I made var_dump($request) but the structure is unmanageably large. Actually I am suscpicous about this tutorial - do we really need to list all the fields in the standard update procedure?

like image 816
TomR Avatar asked Jul 12 '16 19:07

TomR


1 Answers

You can access the input data with:

$input = $request->all();

https://laravel.com/docs/5.2/requests#retrieving-input

However, I've also had to get the input in this manner when using AngularJS $http module:

$input = file_get_contents('php://input');
like image 178
swatkins Avatar answered Sep 24 '22 01:09

swatkins