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?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community