Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changes to Input::json() function between Laravel 4 beta3 and beta4

When I was developing in Laravel4 Beta3, I used to get JSON POST data from a service using Input::json() function, But when I updated to Laravel4 Beta4, I am getting following error:

Notice: Undefined property: Symfony\Component\HttpFoundation\ParameterBag::$productName in /Applications/MAMP/htdocs/commonDBAPI/app/controllers/UserController.php line 47

Does any one have any idea, what could be the reason.

Thanks,

like image 657
Sameer Avatar asked Apr 04 '13 20:04

Sameer


1 Answers

You can access just the JSON using Input::json()->all().

JSON input is also merged into Input::all() (and Input::get('key', 'default')) so you can use the same interface to get Query string data, Form data and a JSON payload.

The documentation does not yet reflect all changes because Laravel 4 is still in beta and the focus is on getting the code right, the documentation will be updated ready for the public release.


How is JSON merged with Input::all()?

Consider the following JSON:

{
    'name': 'Phill Sparks',
    'location': 'England',
    'skills': [
        'PHP',
        'MySQL',
        'Laravel'
    ],
    'jobs': [
        {
            'org': 'Laravel',
            'role': 'Quality Team',
            'since': 2012
        }
    ]
}

When merged into Laravel's input the JSON is decoded, and the top-level keys become top-level keys in the input. For example:

Input::get('name'); // string
Input::get('skills'); // array
Input::get('jobs.0'); // object
Input::all(); // Full structure of JSON, plus other input
like image 112
Phill Sparks Avatar answered Dec 22 '22 21:12

Phill Sparks