I am creating an API using Laravel 5.2 and I have a model class named Post
when i get a request from client in my PostController
i have a JsonObject
like this:
{
"description": "My description is here!",
"items": [
{
"text": "This is the item and the the sort is 0",
"type": 1,
"sort": 2
},
{
"type": 2,
"path": "exmple.com",
"sort": 3
}
],
"title": "My title",
"tags": [
{
"name": "Tag number #1"
},
{
"name": "Tag number #2"
},
{
"name": "Tag number #3"
}
],
"user_id": 1
}
in my PostController
public function store(Request $request) {
$jsonObject = json_decode($request->getContent()); // i get jsonObject here
$post= new Post();
// what to do here?
}
Relationships
What i want to do:
save this new post using the received JsonObject
with related data
Note: other model classes like Tag and Item are ready to use.