changed inserting method into the database

- this should be changed back later on once we finalised the fillable/guard fields on model classes.
This commit is contained in:
pushrbx 2023-02-11 19:25:02 +00:00
parent 35ffd32e27
commit b35f37a0a9

View File

@ -57,7 +57,19 @@ class DatabaseRepository extends RepositoryQuery implements Repository
// this way we trigger scout to index records in the search index.
$modelClass = $this->getModelClass();
/** @noinspection PhpUndefinedMethodInspection */
$modelClass::create($attributes);
$modelInstance = new $modelClass();
// fixme: change this to $modelClass::create() call, because that one protects against
// mass assignment. This way of doing it is just a work around to make sure all attributes
// land in the database. The "fillable" and "guard" fields of models should be populated
// correctly.
$modelInstance->fill($attributes);
foreach(["request_hash", "modifiedAt", "createdAt"] as $metaField) {
if (array_key_exists($metaField, $attributes)) {
$modelInstance->$metaField = $attributes[$metaField];
}
}
$modelInstance->save();
return true;
}