我正在使用laravel-mongodb库(https://github.com/jenssegers/laravel-mongodb)
当我想创建新记录时,我收到此错误:
strlen() expects parameter 1 to be string, array given
在project.local / vendor / mongodb / mongodb / src / Collection.php:104
这是型号: Category.php
namespace App\Models;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Category extends Eloquent
{
protected $collection = [ 'categories' ];
protected $fillable = [ 'name', 'parentId' ];
}
这是我的商店方法:
public function store(Request $request)
{
// e1: Category::create([ 'name' => 'T-shirts' ]);
$n = new Category;
$n->name = 'T-shirts';
$n->save();
return back();
}
答案 0 :(得分:1)
将您的$ collection更改为string,您已将其设置为数组,这就是您收到该错误的原因
$collection = 'categories';
以下是来自库github自述文件
的示例use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent {
protected $collection = 'users_collection';
}