简体   繁体   中英

Database column won't update Laravel Eloquent

my column " conversion_rate " won't update, my " iso " column updates without any problem. I tried changing the column's type in the model but nothing helps.

    $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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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