Help us understand the problem. What is going on with this article?

LaravelのEloquentモデルでupdated_atがないテーブルを使う方法

Eloquentモデルは作成時に自動でcreated_atとupdated_atを更新してくれるようになっているので、updated_atがないテーブルでデータを登録しようとすると、こんな感じで怒られる。

Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `positions` (`name`, `order_number`, `updated_at`, `created_at`) values (test, 17, 2020-08-22 07:58:07, 2020-08-22 07:58:07))
http://localhost/positions/create

updated_atテーブルがないテーブルで登録したい場合はデータクラスに以下を追加すると、created_atとupdated_atの更新を無効にできます。

Positions.php
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Position extends Model
{
    public $timestamps = false; // 追加
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした