1
我使用Laravel 4.2.*
我有一个User
模型,其中insert()
方法工作正常,但是当我使用create()
方法时抛出一个错误:Laravel 4.2雄辩创建:数组字符串转换错误
Array to string conversion
我的模型:
class User extends Eloquent{
public $table = 'users';
protected $primaryKey = 'user_id';
protected $fillable = ['first_name', 'last_name', 'created_by'];
public function insertUserInfo($data)
{
//return self::insert($data); //working with no error but not adding `created_at`
return self::create($data); //Array to string conversion
}
}
的样本数据:
$data = [
'first_name' => 'Jhon',
'last_name' => 'Doe',
'created_by' => Auth::id() // var_dump(Auth::id()) => int(11)
];
如果有人可以帮助我为什么create()
发生错误,这将是有益的。
PHP v5.6.3
EDITED
我可以保证有内部$data
没有数组值。而$data
正在使用insert()
,但在使用create()
或save()
方法时抛出错误。
'的var_dump($数据)'或许真的不是你认为它应该是。 – aynber
@aynber:雅我已经检查过,但所有的字段都如预期,而且相同的数据集正在使用'insert'方法。 –
也许'Auth :: id()'返回一个数组... –