超载属性的间接修改 Laravel MongoDB
我正在将MongoDB与Laravel一起使用。我有一个名为的集合,其中包含一个文档categories
[
{
"_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"
}
]
我正在尝试创建一个函数,将细节添加到上述文档中的 specifics 数组中。
这是我的请求正文
HTTP: POST
{
"specifics": [
"material"
]
}
我正在使用以下函数处理此请求
/**
* 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);
}
但是当我打这个电话时,我得到错误
错误类别控制器中的异常.php行 101:间接修改重载属性 App\类别::$specifics不起作用
请帮我解决这个问题。
我正在使用 https://github.com/jenssegers/laravel-mongodb MongoDB的这个软件包。