2017-02-15 53 views
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()方法時拋出錯誤。

+0

'的var_dump($數據)'或許真的不是你認爲它應該是。 – aynber

+0

@aynber:雅我已經檢查過,但所有的字段都如預期,而且相同的數據集正在使用'insert'方法。 –

+0

也許'Auth :: id()'返回一個數組... –

回答

1

添加array類型提示:

public function insertUserInfo(array $data) 
{ 
    return self::create($data); 
} 
+0

嘗試過,但成功,仍然出現錯誤。 –