5

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?

3
  • 1
    If you find it complicated to read a var_dump from the object size; do this: echo '<pre>' . print_r($request) . '</pre>'; Commented Jul 12, 2016 at 19:37
  • 1
    or in laravel: dd($request); Commented Jul 12, 2016 at 19:38
  • you can try dd($request->all()) instead... Commented Jul 12, 2016 at 21:55

3 Answers 3

4

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');
Sign up to request clarification or add additional context in comments.

1 Comment

var_dump($request->all()) gives array(0) { }. This is strange because I am making test PUT request with body data from "I'm Only Resting" program. Where the body gets lost?
2

for get all input

try it

$request = \Input::all();

Comments

1

If you want to fetch individual parameters from request object the you can do that with input Method of Request Class.

$request->input("parameter_name");

But if you want to fetch all request parameters then you can use all method which will return you an array of all the request key-value pairs

$request->all()

The thing you are missed is, you are calling $request->input which is null because input is method of Request class and not a property

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.