在Laravel中保存数据时如何禁用updated_at和created_at

Nik*_*nov 0 php model laravel eloquent

我试图将数据保存在模型函数中。使用模型的save()函数时,出现如下错误。

照射\数据库\ QueryException:SQLSTATE [42S22]:柱未找到:1054未知列'的updated_at'在'字段列表'(SQL:插入到account_typesnameupdated_atcreated_at)的值(设备厂,2019年8月5日五时33分57秒, 2019-08-05 05:33:57))在文件F:\ HTML&

我已删除表coz中的created_at和updated_at列,我不需要它。我想知道在Laravel中使用模型save()函数时如何禁用created_at和update_at数据保存。

<?php

namespace pshub;

use Illuminate\Database\Eloquent\Model;

class AccountType extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name'];

    // Create Type Function
    public function createType($type) {
        $existence = $this->where('name', $type)->get();

        if (sizeof($existence) > 0) {
            return $this->where('name', $type);
        } else {
            $this->name = $type;
            $this->save();
            return $this->id;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

nak*_*kov 5

只需添加:

public $timestamps = false;
Run Code Online (Sandbox Code Playgroud)

在您的模型中,您一切顺利。