I am using MongoDB with Laravel. I have a collection called categories
which has one document
[
{
"_id": "567dc4b4279871d0068b4568",
"name": "Fashion",
"images": "http://example.com/1.jpg",
"specifics": [
"made"
],
"brands": [
{
"name": "Giordano",
"logo": "http://example.com/"
},
{
"name": "Armani",
"logo": "http://example.com/"
}
],
"updated_at": "2015-12-25 22:40:44",
"created_at": "2015-12-25 22:35:32"
}
]
I am trying to make a function that add specifics to the specifics array in the above document.
Here is how my request body is
HTTP: POST
{
"specifics": [
"material"
]
}
And i am handling this request with the following function
/**
* Add specs to category
* @param string $category_id
* @return Illuminate\Http\JsonResponse
*/
public function addSpecifics($category_id)
{
$category = $this->category->findOrFail($category_id);
$category->specifics[] = $this->request->get('specifics');
$status_code = config('http.UPDATED');
return response()->json($category->save(), $status_code);
}
But when i hit this call, I get error of
ErrorException in CategoryController.php line 101: Indirect modification of overloaded property App\Category::$specifics has no effect
Please help me in fixing this.
I am using https://github.com/jenssegers/laravel-mongodb this package for MongoDB.