Create method saving null values

Posted 3 months ago by bcharron

I have a save method in a repository in an application that I am working on. The method looks like this:

public function save($data)
    {

        Model::create([
            'title' => $data['title'],
            'min_length' => $data['min_length'],
            'max_length' => $data['max_length'],
            'prefix' => $data['prefix'],
            'one_way' => $data['one_way']
        ]);

    }

When I call this method, it returns the saved model, but all of the values in it are empty. I have confirmed that the values are present in $data by dd'ing them. I have the $fillable property set on the model, but still I am getting null values:

protected $fillable = [

        'title',
        'min_length',
        'max_length',
        'prefix',
        'one_way',

    ];

I have changed this to use the save() method instead of create() and it works. Can anyone explain why the create method does not save the values?

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.