Laravel post with content type json
Ad
I'm working with laravel 5 framework, i want to create a rest API and i'm getting some problems.
I have a method post that receives Json and i can't access that content, always say is []
or null
That's my controller function:
public function Register()
{
$teste = Request::json()->all();
$name=$teste['wtf'];
return $name;
}
That returns me this error "Undefined index: wtf" because the array $teste is null
How can I receive JSON properly?
Ad
Answer
Ad
From the image you showed in the comment, I realize that the data you are sending is as form-data
and not JSON
. Please select raw
option and choose json
instead of text
from drop down and retry what @Moppo said
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad