I have tried to save data in the model function. When using save() function of the model, I see some error such as below.
Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into
account_types(name,updated_at,created_at) values (manufactuer, 2019-08-05 05:33:57, 2019-08-05 05:33:57)) in file F:\HTML&
I have deleted created_at and updated_at columns in the table coz I don't need it. I want to know how I can disable created_at and update_at data saving when using model save() function in the Laravel.
<?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;
        }
    }
}
                Just add this:
public $timestamps = false;
In your model and you are good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With