I'm using Laravel 4.2.* I have a User Model where insert() method is working normally but when I'm using create() method it is throwing an error:
Array to string conversion
My model:
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
}
}
Sample data:
$data = [
'first_name' => 'Jhon',
'last_name' => 'Doe',
'created_by' => Auth::id() // var_dump(Auth::id()) => int(11)
];
It 'll be helpful if anyone can help me as why create() is throwing an error.
PHP v5.6.3
EDITED
I can assure that there is no array value inside $data. and the same $data is working with insert() but throwing error when using create() or save() method.
var_dump($data)maybe something isn't what you think it should be.insertmethod.Auth::id()is returning an array ...$user = new User($data);then$user->save();