简体   繁体   English

数据库列不会更新 Laravel Eloquent

[英]Database column won't update Laravel Eloquent

my column " conversion_rate " won't update, my " iso " column updates without any problem.我的列“ conversion_rate ”不会更新,我的“ iso ”列更新没有任何问题。 I tried changing the column's type in the model but nothing helps.我尝试更改 model 中列的类型,但没有任何帮助。

    $feed = simpleXML_load_file($url,LIBXML_NOCDATA);
        foreach ($feed->list->currency as $currency) {
            if (Currency::all()->contains('iso', $currency['iso_code'])) {
                Currency::where("iso", $currency['iso_code'])->get()->first()->update(['conversion_rate' => 2.00]);
            }
        }

edit: My database stucture编辑:我的数据库结构

    Schema::create('currencies', function (Blueprint $table) {
        $table->id();
        $table->string('iso');
        $table->decimal('conversion_rate');
        $table->timestamps();
    });

You should add your fields in model fillable property.您应该在model 可填写属性中添加您的字段。

    class Currency extends Model
    {
        use HasFactory;
    
        /**
         * @var string
         */
        protected $table = 'currencies';
    
        /**
         * @var string[]
         */
        protected $fillable = ['iso', 'conversion_rate'];
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM