Support the ongoing development of Laravel.io →
Database Eloquent

I've been struggling as to why my "create" method was not saving as a mass assignment.

Mytable::create([
            'title' => $request->get('title'),
            'content' => $request->get('content'),
        ]);

which was for awhile did not save, but only the 'updated_at', 'created_at' columns.

As it turned out, in model class (i.e. class Mytable extends Model{}), I had overwritten the constructor.

public function __construct()
{
$this->setTable('mytables');
}

However, after taken the child construct out, mass assign now works.

It seems if I want to override the construct function in my model, I must include this code:

public function __construct($attributes = [])
{
	$this->bootIfNotBooted();

    $this->syncOriginal();

    $this->fill($attributes);

	$this->setTable('mytables');
 }

Anyone know why is that?

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

webtest01 webtest01 Joined 11 Oct 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.