-
Notifications
You must be signed in to change notification settings - Fork 921
Description
What I did
Enabled Laravel’s Model::preventSilentlyDiscardingAttributes()
and used dot-notation fields for a one-to-one (morphOne) relationship in a CRUD form.
Minimal example:
// Parent model
class ParentModel extends \Illuminate\Database\Eloquent\Model
{
protected $fillable = ['field_one', 'field_two']; // note: no 'relatedMeta' here
public function relatedMeta(): \Illuminate\Database\Eloquent\Relations\MorphOne
{
return $this->morphOne(RelatedMeta::class, 'metable');
}
}
// Related model
class RelatedMeta extends \Illuminate\Database\Eloquent\Model
{
protected $guarded = []; // for simplicity
public function metable(): \Illuminate\Database\Eloquent\Relations\MorphTo
{
return $this->morphTo();
}
}
CRUD fields (Create/Update):
CRUD::field('relatedMeta.attribute_one')->type('text')->label('Attribute One');
Then I opened the Create/Update form, filled relatedMeta.attribute_one, and clicked Save.
What I expected to happen
Backpack should persist dotted fields for hasOne/morphOne to the related model and not pass the relationship root key (relatedMeta) into $parent->fill().
What happened
Laravel threw a Mass Assignment exception because a top-level relatedMeta key was sent to the parent model’s fill() while Model::preventSilentlyDiscardingAttributes() was enabled:
Add fillable property [relatedMeta] to allow mass assignment on [App\Models\ParentModel].
If I disable Model::preventSilentlyDiscardingAttributes(), the same form saves correctly and the related model is updated as documented.
What I've already tried to fix it
- Renamed the relation (e.g., relatedMeta → meta) — same result.
- Added ->entity('relatedMeta') to the field — same result.
- Ensured no accessors/casts/appends named relatedMeta on the parent model.
- Confirmed the relationship methods are standard (morphOne / morphTo) and work for loading.
Is it a bug in the latest version of Backpack?
After I run composer update backpack/crud
the bug is it still there.
Backpack, Laravel, PHP, DB version
PHP VERSION:
8.4.10
PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, apcu, bcmath, bz2, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, igbinary, imagick, intl, ldap, exif, msgpack, mysqli, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, readline, shmop, SimpleXML, soap, sockets, sqlite3, sysvmsg, sysvsem, sysvshm, tokenizer, uploadprogress, xmlreader, xmlrpc, xmlwriter, xsl, zip, memcached, redis, Zend OPcache
LARAVEL VERSION:
12.25.0.0
BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.3.9
backpack/crud: 6.8.5
backpack/generators: v4.0.7
backpack/theme-tabler: 1.2.18
Metadata
Metadata
Assignees
Labels
Type
Projects
Status