在我的Eloquent Model上调用的fill方法不会更新对象属性,而是允许访问这些属性,就好像它是一个数组一样。这是期望的行为,如果是,为什么?
您可以在php artisan tinker
class MyTestClass extends Illuminate\Database\Eloquent\Model {
protected $fillable = ['testArrayProperty', 'testPrimitiveProperty', 'testObjectProperty'];
public $testArrayProperty;
public $testObjectProperty;
public $testPrimitiveProperty;
}
$object = new MyTestClass;
$testObject = new stdClass();
$testObject->test = 'Test';
$object->fill(["testArrayProperty" => ["testKey" => "testValue"], "testObjectProperty" => $testObject, "testPrimitiveProperty" => "test" ]);
$object->testArrayProperty; //returns null
$object["testArrayProperty"];
$object->testObjectProperty; //returns null
$object["testObjectProperty"];
$object->testPrimitiveProperty; //returns null
$object["testPrimitiveProperty"];