【发布时间】:2015-12-25 22:48:55
【问题描述】:
我将 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"
}
]
我正在尝试创建一个函数,将细节添加到上述文档中的具体数组中。
这是我的请求正文
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);
}
但是当我打这个电话时,我得到了
的错误CategoryController.php 第 101 行中的 ErrorException:间接 重载属性 App\Category::$specifics 的修改没有 效果
请帮我解决这个问题。
我正在为 MongoDB 使用 https://github.com/jenssegers/laravel-mongodb 这个包。
【问题讨论】:
-
这里不限也不关mongodb,而是和eloquent和php有关
标签: php mongodb laravel laravel-5