Eloquent Create Method - Always inserts blank entries.

Posted 4 years ago by industrious

Has anyone experienced an issue where Laravel refuses to insert data when using the Model::create() method?

I know it's nothing to do with the fields not being mass-assignable (http://stackoverflow.com/questions/15659708/laravel-4-eloquent-mass-assignment-creates-empty-records-after-update), because I've got the $fillable property set correctly on the model. I can also use the fill method (and save) to insert data on that model, it's just the create method that doesn't seem to insert anything..

To verify it's not to do with being mass assignable, I've also done:

Client::unguard();
Client::create($data);
Client::reguard();

Which still doesn't work..

In Eloquent/Model.php:

public static function create(array $attributes)
{
 $model = new static($attributes);

 $model->save();

 return $model;
}

If I output the first argument, the attributes are there, it just seems to be when the new class is instantiated it doesn't fill the properties for some reason..

This is actually on L5, but I have had the same on L4 as well.

Thanks in advance!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.